Skip to content

Open-source social media scheduler built for AI agents and the teams behind them. Create, schedule and publish posts to every network through MCP or the REST API, or write them yourself in a composer your team will love.

Defer PostCreated with DB::afterCommit in the observer.

Paulo Castellano2aef07dde6f5
diff --git a/app/Events/PostCreated.php b/app/Events/PostCreated.php
index 6234ba0ee..013f20d50 100644
--- a/app/Events/PostCreated.php
+++ b/app/Events/PostCreated.php
@@ -8,11 +8,10 @@ use App\Models\Post;
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 be6a3e6c0..1486cfc04 100644
--- a/app/Observers/PostObserver.php
+++ b/app/Observers/PostObserver.php
@@ -9,12 +9,13 @@ use App\Enums\Post\Status as PostStatus;
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