how to delete multiple ids in laravel?

Viewed 177

my table name is paids and i want to delete all the ids which have same ot_id here is my databsae

i have data like this

 |id|  |ot_id|
   1      20
   2      20
   3      20
   4      20
   5      20
   6      20
public function deleteOT($id)
{
    $deleteid = Paid::where();
    return Common::Message("Order Taker", 3);
}

here i want to delete how i can do that in laravel?

3 Answers

You should spend some time reading Laravel docs, which are very good source for learning the basics.

public function deleteOt($id)
{
    Paid::where('ot_id', $id)->delete();

    return Common::Message("Order Taker", 3);
}

To select multiple rows at once you can use, whereIn()

public function deleteOt($id)
{
   Paid::whereIn('id', $ids)->delete();
   return Common::Message("Order Taker", 3);
}
1. $id => it should be an array when you delete multiple ids.

     public function deleteOt($id) {
           Paid::whereIn('id', $ids)->delete();
           return Common::Message("Order Taker", 3);
     }
Related