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
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);