Level 39
Yes query builder does not generate event.
1 like
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello everybody,
given the situation where I have a model with a relation like this:
/**
* @return MorphMany
*/
public function notifications(): MorphMany
{
return $this->morphMany(Notification::class, 'notifiable')->orderBy(
'created_at',
'desc'
);
}
Now I'd like to delete all related notifications and, this is important, trigger the deleting-event on each of the deleted items, can I do this like this:
$user->notifications()->delete();
or do I have to do
$user->notifications->each(function($notification){
$notification->delete();
});
The second example makes use of src/Illuminate/Database/Eloquent/Model.php's delete-method, which contains $this->fireModelEvent('deleting') - the first example makes use of the query builder, so I guess the deleting-event will not be fired.
Is my assumption correct?
Please or to participate in this conversation.