Laravel 11.30 Released
Published on by Paul Redmond
This week, the Laravel team released v11.30, which includes defer testing helpers, the ability to define custom unique string IDs for Eloquent models, the use of backed Enums with AuthorizesRequests
, and more.
withDefer()
and withoutDefer()
Test Helpers
New Tim MacDonald contributed a withoutDefer()
and withDefer()
test helpers. Using withoutDefer()
is helpful when you are working with tests use defer, but you want to disable it to assert the outcome of the deferred call:
// ❌ will not workUser::create(/* ... */); $this->assertAgainstSomeDeferredOutcome(); // ✅ Will work$this->withoutDefer(); User::create(/* ... */); $this->assertAgainstSomeDeferredOutcome();
See Pull Request #53340 for implementation on details on how these helpers work.
HasUniqueStringIds
Trait
Introduce Luke Kuzmish updated the code around HasUuids
and HasUlid
eloquent traits so that you can use custom unique string IDs as route keys without having to override resolveRouteBindingQuery()
. Here's an example of how you could customize the types of unique strings your model uses:
trait HasTwrnsTrait{ use HasUniqueStringIds; public function newUniqueId() { return (string) Twrn::new(); } protected function isValidKey($value): bool { return Twrn::isValid($value); }}
This update doesn't introduce any breaking changes as the HasUuids
and HasUlid
model concerns now use the use HasUniqueStringIds
trait. See Pull Request #53280 for more details.
authorize()
Method to Accept Enums
Allow Johan van Helden updated the AuthorizesRequests
trait to accept backed enums directly. Laravel has recently received multiple updates to allow direct use of Enums in various parts of the framework. Here's an example of using an Enum with the authorize()
method:
enum DashboardPermission: string{ case VIEW = 'dashboard.view';} // Beforepublic function index(): Response{ $this->authorize(DashboardPermission::VIEW->value); //} // Afterpublic function index(): Response{ $this->authorize(DashboardPermission::VIEW); //}
Release notes
You can see the complete list of new features and updates below and the diff between 11.29.0 and 11.30.0 on GitHub. The following release notes are directly from the changelog:
v11.30.0
- Add
$bind
parameter toBlade::directive
by @hossein-zare in https://github.com/laravel/framework/pull/53279 - [11.x] Fix
trans_choice()
when translation replacement include|
separator by @crynobone in https://github.com/laravel/framework/pull/53331 - [11.x] Allow the authorize method to accept Backed Enums directly by @johanvanhelden in https://github.com/laravel/framework/pull/53330
- [11.x] use
exists()
instead ofcount()
by @browner12 in https://github.com/laravel/framework/pull/53328 - [11.x] Docblock Improvements by @mtlukaszczyk in https://github.com/laravel/framework/pull/53325
- Allow for custom Postgres operators to be added by @boris-glumpler in https://github.com/laravel/framework/pull/53324
- [11.x] Support Optional Dimensions for
vector
Column Type by @akr4m in https://github.com/laravel/framework/pull/53316 - [11.x] Test Improvements by @saMahmoudzadeh in https://github.com/laravel/framework/pull/53306
- [11.x] Added
dropColumnsIfExists
,dropColumnIfExists
anddropForeignIfExists
by @eusonlito in https://github.com/laravel/framework/pull/53305 - [11.x] Provide an error message for PostTooLargeException by @patrickomeara in https://github.com/laravel/framework/pull/53301
- [11.x] Fix integrity constraint violation on failed_jobs_uuid_unique by @bytestream in https://github.com/laravel/framework/pull/53264
- Revert "[11.x] Added
dropColumnsIfExists
,dropColumnIfExists
anddropForeignIfExists
" by @taylorotwell in https://github.com/laravel/framework/pull/53338 - [11.x] Introduce
HasUniqueStringIds
by @cosmastech in https://github.com/laravel/framework/pull/53280 - [11.x] Refactor: check for contextual attribute before getting parameter class name by @korkoshko in https://github.com/laravel/framework/pull/53339
- [11.x] Pick up existing views and markdowns when creating mails by @kevinb1989 in https://github.com/laravel/framework/pull/53308
- [11.x] Add withoutDefer and withDefer testing helpers by @timacdonald in https://github.com/laravel/framework/pull/53340