Home >Backend Development >PHP Tutorial >laravel destroy multiple delete and single delete selection

laravel destroy multiple delete and single delete selection

WBOY
WBOYOriginal
2016-10-11 14:23:351810browse

A destroy code in laravel

<code>public function destroy($id)
{
    //.......
    
    $this->model->destroy($id);
    
    // ........
}</code>

Thinking about destroy, this method is for single deletion,
But for multiple deletions, consider the following method:
1. $id can be switched to a similar format of 1, 2, 3, 4, and then processed into an array in the function , delete
2. POST is submitted to function $_POST['ids'], but the $id in destroy is in name only, because $id is not used at all.

I don’t know how everyone usually decides, it’s so confusing

Reply content:

A destroy code in laravel

<code>public function destroy($id)
{
    //.......
    
    $this->model->destroy($id);
    
    // ........
}</code>

Regarding destroy, we have the following thoughts. This method is for single deletion,
but for multiple deletions, consider the following methods:
1. $id can be switched to a similar format of 1, 2, 3, 4, and then processed into an array in the function , delete
2. POST is submitted to function $_POST['ids'], but the $id in destroy is in name only, because $id is not used at all.

I don’t know how everyone usually decides, it’s so confusing

Everything should be treated as an array or a string. Just convert this into an array in advance in the method

public function destroy(array $id)
{

<code>//.......

$this->model->destroy($id);

// ........</code>

}

Anyway, destroy supports arrays

AppFlight::destroy(1);
AppFlight::destroy([1, 2, 3]);
AppFlight::destroy(1, 2, 3);

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn