2

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 3

3

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);
}
Sign up to request clarification or add additional context in comments.

Comments

2

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 Comment

Please add some explanation to your answer such that others can learn from it
0
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);
     }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.