[12.x] Add ability to prepend() and append() to PendingChain#56536
Merged
taylorotwell merged 4 commits intoAug 4, 2025
Conversation
stevebauman
commented
Aug 4, 2025
| * @return \Illuminate\Foundation\Bus\PendingChain | ||
| */ | ||
| public function chain($jobs) | ||
| public function chain($jobs = null) |
Contributor
Author
There was a problem hiding this comment.
This was intentionally changed so developers can make chains without any initial argument:
$chain = Bus::chain();
$chain->append(...);
$chain->prepend(...);
$chain->dispatch();If you'd rather avoid this, let me know!
Contributor
There was a problem hiding this comment.
Funny how one can be so trained to see something, that one instantly goes

as in this case: when() 😅
Bus::chain([
new TranscribeRecording($recording)
])->when(
$this->hasAudioNormalizationEnabled(),
fn ($chain) => $chain->prepend(new NormalizeAudio($recording)),
)->when(
$this->hasTranscriptionRedactionEnabled(),
fn ($chain) => $chain->append(new RedactTranscription($recording)),
)->dispatch();
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description:
This PR adds the ability to prepend and append jobs on a Bus
PendingChain, giving developers the ability to conditionally transform the chain before its dispatched.Example:
In the example above:
NormalizeAudiojob will be moved to the first position of the chain and theTranscribeRecordingjob will be moved to the secondLet me know your thoughts! Thanks for your time 🙏