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
  • 58,060
  • 25
  • 98
  • 150
user1995781
  • 19,085
  • 45
  • 135
  • 236

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
  • 214,931
  • 59
  • 362
  • 292