
Laravel 13.44.0 is a small release on paper. It adds a few helpers, fixes a long list of edge cases and supports PHP 8.6. But three of the changes touch how an application talks to its database, and those are the ones worth a closer look before you upgrade.
Slow transactions now have a hook
The release adds DB::whenTransactionRunsLongerThan(). You give it an interval and a callback. When the outermost transaction commits or rolls back, and it ran longer than the interval, the callback fires. According to the release notes, nested transactions are not timed separately, and a plain number is read as milliseconds.
This matters because long transactions are a quiet source of trouble. They hold locks, they block other writers, and they rarely show up in a test run. Until now most teams found them through a slow-query log or an angry user.
A few points of judgement:
- The callback runs after the transaction ends. It reports the problem. It does not stop it.
- Pick a threshold from what your own code normally does. A number copied from an example tells you little.
- Send the result to your logs or metrics with the connection name and the outcome. A warning with no context is noise.
- Watch for transactions that wrap an HTTP call or a file upload. Those are the usual culprits.
A lighter lock for PostgreSQL
The second change is lockForNoKeyUpdate() on the query builder. The release notes explain the problem. On PostgreSQL, lockForUpdate() also blocks the lock that a foreign key check takes. So while you hold a parent row, inserting a child row that points to it has to wait. Two transactions can end up in a deadlock.
The new method takes a weaker lock that does not get in the way of those inserts. On MySQL, SQLite and SQL Server it behaves the same as lockForUpdate(), so you can call it on any driver.
If you run PostgreSQL, search your code for lockForUpdate() on rows that other code references through foreign keys. Teams, accounts and orders are typical examples. Where you only change the row's own columns and never its key, the lighter lock is the better fit. Do not switch blindly. If you update the key itself, you still need the stronger lock. Check each case, and test under concurrent load if the code is on a hot path.
Model lookups in form requests
Form requests now have model(), modelOrFail() and models(). They load Eloquent models from IDs found in the input. If you leave out the class, Laravel guesses it from the key, so user_id resolves to the User model.
This removes a few lines of boilerplate. It also moves a database query into the request layer, and we would be careful with that.
- Guessing the class from the key is short, but it hides a link between a field name and a model. Passing the class explicitly costs little and reads better in review.
- A lookup by ID is not an authorization check. Loading a record does not mean the current user may touch it. Keep your policies in place.
- The release also includes a follow-up fix so that array input is ignored by
model()andmodelOrFail(). That is a reminder that request input is untrusted, even when it looks like an ID.
Use the helpers for simple, repeated lookups. Keep complex queries in your own code, where they are easy to find.
The smaller items
Several other changes are worth a glance.
migrateandmigrate:freshaccept--schema-only. Laravel loads the schema dump and skips the migrations that would run after it. This helps with test connections whose migrations run separately.copyToDisk()andmoveToDisk()accept options, such as visibility or S3 headers, when moving a file to S3.- PHP 8.6 deprecations are fixed, including the
SORT_LOCALE_STRINGflag andstrcoll(). - The list also includes security-related fixes, among them a file validation bypass and attribute escaping in Markdown mail. Both were listed for the 12.x line too, which is a good reason to read the full notes if you are not yet on 13.
If you plan to move to PHP 8.6, run your test suite with deprecation notices turned into errors. Framework support is only half of it. Your own code and your packages may still use the old calls.
What to do next
Upgrade in a branch and run your tests. Then do two small things. Add a long-transaction callback with a threshold you chose, and review your lockForUpdate() calls if you use PostgreSQL. Both give you a better view of how your database behaves under load, and that is worth more than any new helper.
Source: Laravel News
