1

I am developing a Laravel application.

There are a lot of CRUD sample application on the internet.

Most of them are like this,

  • create GET articles/create
  • update POST articles/store
  • edit GET articles/{id}/edit
  • show GET articles/{id}
  • delete POST articles/{id}/destroy

Generally it works fine.

But as for delete, I am developing an application that can enable multiple row deletion at once.

I tried to loop this function for the first time, and found that it is not good idea to execute form post again and again.

<form method="post" action="/articles/{{$aaa->id}}/destroy">
      <input type="hidden" name="_token" value="{{csrf_token()}}">         
</form>

How do I delete many rows at once in my Laravel application?

Are there any solutions?

Shoji Urashita
  • 826
  • 2
  • 11
  • 22
  • 1
    If you're using 4.1 then may be it will be solution http://stackoverflow.com/questions/23624630/mass-delete-in-laravel-4-1-based-on-array-of-ids-or-objects – Ayaz Ali Shah Feb 09 '16 at 07:08

2 Answers2

3

Possible option can be.

$ids_to_delete = array("1","5","8");
DB::table('table_name')->whereIn('id', $ids_to_delete)->delete(); 

$ids_to_delete = array("1","5","8");
Table::destroy($ids_to_delete);

Thanks Amit

Amit Shah
  • 1,380
  • 1
  • 10
  • 19
2

I think you have to make array of the delete "id" and send it to the destroy method regarding controller.

public function destroy($id)
{
    Case::find(explode(',', $id))->delete();
 }

OR

 Case::destroy($ids);

Hope this is help.

Thnaks.

Yagnik Detroja
  • 921
  • 1
  • 7
  • 22