Search code examples
laravel-5.3

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


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


Solution

  • 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();