Skip to content

[12.x] Ensure Bus::chain filters out falsy items#58369

Merged
taylorotwell merged 7 commits into
laravel:12.xfrom
jackbayliss:12x-clear-falsy-chained
Jan 15, 2026
Merged

[12.x] Ensure Bus::chain filters out falsy items#58369
taylorotwell merged 7 commits into
laravel:12.xfrom
jackbayliss:12x-clear-falsy-chained

Conversation

@jackbayliss

@jackbayliss jackbayliss commented Jan 13, 2026

Copy link
Copy Markdown
Contributor

Bus::batch() does this - so feels natural (to me) that chain should too.. as it feels pointless keeping any null or empty values in the chain.

When it's serialized this should also help reduce the size - if anyone is currently doing this.

I've done this in prepareNestedBatches as it keeps the logic centralised. it also means append / prepend benefit from it too.

This means we can now do an inline chain like..

Bus::chain([
    new ProcessOrder($order),
    $order->needsShipping() ? new ShipOrder($order) : null,
    $order->isGift() ? new SendGiftMessage($order) : null,
    new SendConfirmationEmail($order),
])->dispatch();


Bus::assertChained(function (PendingChain $chain) {
    $jobs = array_filter($chain->jobs); // won't need to do this anymore.
    return count($jobs) === 2;
});

I think I've covered it in tests, but happy to target 13.x if this is a bit risky for 12.x

@github-actions

Copy link
Copy Markdown

Thanks for submitting a PR!

Note that draft PR's are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.

Pull requests that are abandoned in draft may be closed due to inactivity.

@jackbayliss jackbayliss marked this pull request as ready for review January 13, 2026 23:01
@taylorotwell taylorotwell merged commit 2929dec into laravel:12.x Jan 15, 2026
70 checks passed
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.

2 participants