1

When we use resource route, we have the URL to be something like this for doing deletion.

DELETE http://localhost/user/1

How can we do deletion for more than one id in a single request?

Thank you.

tereško
  • 57,247
  • 24
  • 95
  • 149
user1995781
  • 18,215
  • 43
  • 131
  • 229

1 Answers1

2

You'll have to create your own route for that:

Route::delete('users', 'UsersController@deleteMany');
Route::resource('users', 'UsersController');

Then you can send a DELETE request with the ids in the body:

DELETE /users

[1,2,3,4]

Then use that in your controller:

public function deleteMany()
{
    User::whereIn('id', Request::json()->all())->delete();
}
Community
  • 1
  • 1
Joseph Silber
  • 205,539
  • 55
  • 352
  • 286