I tried deleting records by id, but it happens, I have found the last record is deleted

64 views Asked by At

I tried deleting records by id, but it happens, I have found the last record is deleted,

//Index method just
Report::all( ) ;

//Delete mesthod
Report::delete($id);

sorry if very quick question, I use a mobile phone now Thank You

2

There are 2 answers

0
Corvus Crypto On BEST ANSWER

According to the docs, one should find the specific record with a query and perform delete on that.

https://laravel.com/docs/5.3/eloquent#deleting-models

Based on their example your code should be more like:

$record = Record::where('id', $id)->delete();
0
Amit Gupta On

If you have observers which fire on Record delete then you should use Model's delete() method as:

Record::find($id)->delete()

Or you can just use query builder's delete method as:

Record::where('id', $id)->delete()