When I delete a row using this syntax:
$user->delete();
Is there a way to attach a callback of sorts, so that it would e.g. do this auto
It is better if you override the delete
method for this. That way, you can incorporate DB transactions within the delete
method itself. If you use the event way, you will have to cover your call of delete
method with a DB transaction every time you call it.
In your User
model.
public function delete()
{
\DB::beginTransaction();
$this
->photo()
->delete()
;
$result = parent::delete();
\DB::commit();
return $result;
}