Skip to content

[13.x] Add #[AfterCommit] attribute - #61208

Open
xurshudyan wants to merge 9 commits into
laravel:13.xfrom
xurshudyan:should-broadcast-after-commit
Open

[13.x] Add #[AfterCommit] attribute#61208
xurshudyan wants to merge 9 commits into
laravel:13.xfrom
xurshudyan:should-broadcast-after-commit

Conversation

@xurshudyan

@xurshudyan xurshudyan commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

Adds an #[AfterCommit] attribute for deferring queued work until the open database transaction commits.

It works anywhere the $afterCommit property already does — queued jobs, listeners, mailables, notifications and broadcast events — and can still be overridden with public $afterCommit = false; or ->beforeCommit().


namespace Illuminate\Contracts\Broadcasting;

interface ShouldBroadcastAfterCommit extends ShouldBroadcast

@Lukasss93 Lukasss93 Aug 17, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about ShouldBroadcastNow?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After-commit only makes sense for queued broadcasts — ShouldBroadcastNow bypasses the queue, so afterCommit would never be read

@gdebrauwer

Copy link
Copy Markdown
Contributor

Would an #[AfterCommit] attribute not be a better solution than introducing a new interface?

@xurshudyan

Copy link
Copy Markdown
Contributor Author

@gdebrauwer It might be, but it'd need to cover jobs, mailables, notifications and listeners too — they all use interfaces today (ShouldQueueAfterCommit, ShouldDispatchAfterCommit, ShouldHandleEventsAfterCommit), so an attribute only for broadcasts would be inconsistent.

@shaedrich

Copy link
Copy Markdown
Contributor

@xurshudyan If we only ever did what has been done before, there would be no change. Someone always have to make the first step.

@xurshudyan
xurshudyan marked this pull request as draft August 18, 2026 09:24
@xurshudyan xurshudyan changed the title [13.x] Add ShouldBroadcastAfterCommit contract [13.x] Add #[AfterCommit] attribute Aug 18, 2026
@xurshudyan
xurshudyan marked this pull request as ready for review August 18, 2026 11:01
@xurshudyan

xurshudyan commented Aug 18, 2026

Copy link
Copy Markdown
Contributor Author

Here we go again — #[AfterCommit], attempt 3. 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants