diff --git a/app/Events/PostCreated.php b/app/Events/PostCreated.php index 6234ba0e..013f20d5 100644 --- a/app/Events/PostCreated.php +++ b/app/Events/PostCreated.php @@ -8,11 +8,10 @@ use Illuminate\Broadcasting\InteractsWithSockets; use Illuminate\Broadcasting\PrivateChannel; use Illuminate\Contracts\Broadcasting\ShouldBroadcast; -use Illuminate\Contracts\Events\ShouldDispatchAfterCommit; use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Queue\SerializesModels; -class PostCreated implements ShouldBroadcast, ShouldDispatchAfterCommit +class PostCreated implements ShouldBroadcast { use Dispatchable, InteractsWithSockets, SerializesModels; diff --git a/app/Observers/PostObserver.php b/app/Observers/PostObserver.php index be6a3e6c..1486cfc0 100644 --- a/app/Observers/PostObserver.php +++ b/app/Observers/PostObserver.php @@ -9,12 +9,13 @@ use App\Events\PostCreated; use App\Jobs\Automation\DispatchPostTriggerAutomationsJob; use App\Models\Post; +use Illuminate\Support\Facades\DB; class PostObserver { public function created(Post $post): void { - PostCreated::dispatch($post); + DB::afterCommit(fn () => PostCreated::dispatch($post)); } public function saved(Post $post): void