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

laravel destroy multiple delete and single delete selection

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-10-11 14:23:35
Original
1840 people have browsed it

A destroy code in laravel

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

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>
Copy after login
Copy after login

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>
Copy after login

}

Anyway, destroy supports arrays

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

Related labels:
Statement of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template