Support the ongoing development of Laravel.io →
Input Database Forms
Last updated 2 years ago.
0

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. :)

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Snu7z snu7z Joined 24 May 2016

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.