-
Notifications
You must be signed in to change notification settings - Fork 1
ShouldHandleEventsAfterCommit
macropay-solutions edited this page Dec 17, 2025
·
6 revisions
The laravel 10 docs https://laravel.com/docs/10.x/eloquent#observers-and-database-transactions mention this ShouldHandleEventsAfterCommit by giving an example for created event. However this discussion shows that created is the only reasonable example for this to be used. Still this would affect saving and creating events which WILL be fired starting from version 10.55.1 because it makes no sense to fire them after the commit.
Thanks to JaredMezz2 updated events can be handled after commit in this manner:
<?php
namespace App\Observers;
use App\Models\User;
use Illuminate\Support\Facades\DB;
class Observer
{
public function updated(User $model): void
{
$original = $model->getOriginal();
$changes = $model->getChanges();
DB::afterCommit(function() use ($model, $original, $changes): void {
//send email or do something.
});
}
}