One solution is to simply create a route for Mass Deletion, above your resource route, and pass the values via a mass delete form. Other solutions could be purely ajax, but likely the new route will need to be setup, especially if you are using route model binding, which will throw an ModelNotFoundException.
Route::delete('posts/delete','PostController@massDelete');
Route::resource('posts','PostController');
Here's an example of a recent use case in a Admin\UserController.php:
public function massDelete(Request $request)
{
User::destroy(explode(',',$request->ids));
return redirect('admin/users');
}
You will need to utilize some javascript in your view to make things work smoothly, adding all the checked values to a hidden field in the delete form, and to toggle the mass action button/dialog. Don't forget the csrf & method fields so you can post a true DELETE request, or whatever your route is set to listen for.
Like most things with Laravel, there are many ways to get things done, this is just one possible solution. :)
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community