Posts

Showing posts from December 1, 2018

How to soft delete related records when soft deleting a parent record in Laravel?

Image
up vote 12 down vote favorite 1 I have this invoices table that which has the following structure id | name | amount | deleted_at 2 iMac 1500 | NULL and a payments table with the following structure id | invoice_id | amount | deleted_at 2 2 1000 | NULL Invoice Model class Invoice extends Model { use SoftDeletes; } here's the code to delete the invoice public function cance(Request $request,$id) { $record = Invoice::findOrFail($id); $record->delete(); return response()->json([ 'success' => 'OK', ]); } Payments model class Payment extends Model { use SoftDeletes; } The softDelete on Invoice table works perfectly but its related records (payments) still exists.How do I delete them using softDelete? ...