Defer PostCreated with DB::afterCommit in the observer.
Keep after-commit local to created(), matching the saved() job hook, instead of marking the event itself. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
254b7d514b
commit
2aef07dde6
2 changed files with 3 additions and 3 deletions
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue