Back to Blog

Laravel 11.30 Released

Julian Beaujardin
Julian Beaujardin October 31st, 2024

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.

New withDefer() and withoutDefer() Test Helpers

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 work
User::create(/* ... */);

$this->assertAgainstSomeDeferredOutcome();

// ✅ Will work
$this->withoutDefer();

User::create(/* ... */);

$this->assertAgainstSomeDeferredOutcome();

See Pull Request #53340 for implementation on details on how these helpers work.

Introduce HasUniqueStringIds Trait

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.

Allow authorize() Method to Accept Enums

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';
}


// Before
public function index(): Response
{
    $this->authorize(DashboardPermission::VIEW->value);

    //
}

// After
public 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: