I had to do something similar a bit back, it may be a ghetto work-around but it worked for me.
First, I set up a js file and used jquery to record the items checked in the table.
Second, upon clicking delete, I have jquery check to see if # of selections > 1.
Thirdly, if true prevent submission, then use an ajax call to send the array of id's that I pulled from those selections to a controller method.
Lastly, in the controller method (separate from the single delete method) I parse through each id and remove them.
After all is said and done I reload the page to show the results and simulate a form submission.
Let me know if this helps you or at least gives you a better idea on how to do this.
Create an array of checkboxes and use a single for, the trick is to make sure when you name the checkbox you add open and close square brackets [] to the name. This way, even if the user only selects 1 checkbox an array is always returned.
<form action="delete">
@foreach($items as $item)
<input type="checkbox" name=ids_to_delete[]" value="{{$item->id}}" />
@endforeach
</form>
Then to mass delete simple pass the array to the destroy method
ModelToDelete::destroy(Request::get('ids_to_delete'));
@IanSirkit how would I delete a single row? I was thinking about passing a action parameter in the url, but in laravel you can only destroy from a form submit with delete type... I don't like to use ajax for this, because I'm leveraging Session::flash etc for good feedback messages.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community