Skip to content

[12.x] Easily run pipelines inside of a transactions with Pipeline::withinTransaction() #56377

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 23, 2025

Conversation

cosmastech
Copy link
Contributor

@cosmastech cosmastech commented Jul 22, 2025

I feel like it's an incredibly common occurrence to need each of the pipes inside of a Pipeline wrapped inside of a database transaction.

To simplify this, I am suggesting adding a helper method to the Pipeline class so that it wraps pipeline in a transaction.

Pipeline::withinTransaction()
    ->send($user)
    ->through([
        DisableTeamAccessAction::class,
        DisableSchoolAccessAction::class,
        RemoveUserFromGamesAction::class
    ])
    ->then(fn (User $user) => AccountDeactivatedNotification::send($user));

@cosmastech cosmastech marked this pull request as draft July 22, 2025 15:34
@cosmastech
Copy link
Contributor Author

@bert-w your thoughts?

@cosmastech cosmastech force-pushed the pipeline-transaction branch from be33e83 to 3118f23 Compare July 22, 2025 20:20
@cosmastech cosmastech marked this pull request as ready for review July 22, 2025 20:29
@taylorotwell taylorotwell merged commit f753abd into laravel:12.x Jul 23, 2025
60 checks passed
@cosmastech cosmastech changed the title [12.x] Easily run pipelines inside of a transactions with Pipeline::inTransaction() [12.x] Easily run pipelines inside of a transactions with Pipeline::withinTransactions() Jul 23, 2025
@cosmastech cosmastech deleted the pipeline-transaction branch July 23, 2025 14:39
@taylorotwell
Copy link
Member

@cosmastech this probably should be updated to accept a connection name.

@cosmastech
Copy link
Contributor Author

@cosmastech this probably should be updated to accept a connection name.

Do you want me to add that before you release today?

@cosmastech cosmastech changed the title [12.x] Easily run pipelines inside of a transactions with Pipeline::withinTransactions() [12.x] Easily run pipelines inside of a transactions with Pipeline::withinTransaction() Aug 6, 2025
AhmedAlaa4611 referenced this pull request in laravel/docs Aug 6, 2025
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