Overview of Laravel 12.11 Updates Laravel continues to refine the developer experience by removing friction from common tasks. Version 12.11 introduces significant quality-of-life improvements that target three distinct areas: cleaner Blade templates, stricter type safety for array manipulation, and more reliable testing for asynchronous jobs. These updates help developers write more expressive code while catching potential bugs earlier in the lifecycle. Enhancing Blade with Functions and Constants The `@use` directive originally simplified importing classes into views, but it now supports functions and constants. This prevents the need for messy PHP tags or fully qualified names within your markup. ```blade @use('App\Helpers\help', 'App\Helpers\other_helper') @use('App\Constants\UserRoles' as 'Roles') <div> {{ help() }} <p>Status: {{ Roles::ADMIN }}</p> </div> ``` You can also use curly brace syntax to import multiple items from the same namespace, significantly cleaning up the top of your Blade files. Type-Safe Array Getters When working with the Arr helper, static analysis tools often struggle with `mixed` return types. Laravel 12.11 introduces typed getters like `integer()`, `boolean()`, and `float()` to enforce data integrity. ```php $data = ['user' => ['id' => 42, 'is_active' => true]]; // Returns 42 as an integer $id = Arr::integer($data, 'user.id'); // Throws an exception if the value isn't a boolean $active = Arr::boolean($data, 'user.is_active'); ``` These methods ensure that if your data structure changes unexpectedly, your code fails loudly and specifically rather than passing a wrong type downstream. Solving the 'After Response' Testing Hurdle A common pain point involves testing jobs dispatched using `dispatchAfterResponse()`. Since these execute after the response is sent, standard test assertions often fail because the job hasn't run yet. The new `withoutDispatchingAfterResponse()` method on the `Bus` facade forces these jobs to run immediately during the test. ```php public function test_user_is_created() { Bus::withoutDispatchingAfterResponse(); $this->post('/register', [...]); $this->assertDatabaseHas('users', ['email' => '[email protected]']); } ``` Syntax Notes and Best Practices When using the new `@use` directive, remember that PHPStorm might not immediately recognize the curly brace syntax for functions, though it is valid Laravel code. For array helpers, always prefer the typed methods over the generic `Arr::get()` when the expected type is known; this aids tools like PHPStan in verifying your logic without extra docblocks.
Anthony
People
May 2025 • 1 videos
High activity month for Anthony. Laravel among the most active voices, with 1 videos across 1 sources.
May 2025
- May 12, 2025