Laravel 11 DB Transaction and Validation Order Issue #52413
Replies: 1 comment 2 replies
-
What you just posted is just common sense :) |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Laravel Version
11.15.0
PHP Version
8.2.0
Database Driver & Version
Mysql & 5.2.0
Description
In Laravel 10 and previous versions, the following code worked perfectly without any issues. However, in Laravel 11, I encountered a problem when using database transactions with validation.
Issue:
When I add

DB::beginTransaction();
above the validation code, the validation messages do not display in the Blade view file.Steps To Reproduce
Add
DB::beginTransaction();
before the validation logic.Perform validation.
If validation fails, the error messages do not show up in the Blade view file.
Non-working Code:
Solutions:
Solution 1:

Adding
DB::rollBack();
above the redirect statement with errors works.Solution 2:

Moving
DB::beginTransaction();
after handling validation errors works perfectly.Question:
Is this a bug in Laravel 11, or have there been any changes to the database methods that could cause this issue? This code works without any issues in Laravel 10 and previous versions.
Thank you for your time and assistance.
Beta Was this translation helpful? Give feedback.
All reactions