What’s New in Laravel 11.34
14:30, 02.12.2024
Laravel is one of the most popular frameworks for developing web applications in PHP. In Laravel 11.34, the developers introduced important changes to improve the framework's usability, such as the ability to write ordinal numbers in words, conditional traits in routes, the simplified syntax for fake HTTP responses, the Request::fluent() method, and much more.
Major Changes in Laravel 11.34
Writing Ordinal Numbers in Words
The spellOrdinal() method has been added to the Number helper, which allows you to write ordinal numbers in words:
'The ' . Number::spellOrdinal(40) . ' president of the United States is Ronald Reagan';
Conditional Traits to Routes
Added conditional traits to the Route class, allowing you to add conditional logic when defining routes:
Route::middleware('shop') ->domain('{shop}.domain.com') ->when(App::isProduction(), function ($route) { $route->whereIn('shop', app(ShopService::class)->getShopSlugs()); });
Simplified Fake HTTP Responses
Jason McCreary added a simplified syntax for fake HTTP responses, with the ability to use strings for the response body and integers for the status code:
Previously:
// Http::fake([ 'google.com' => Http::response('Hello World'), 'github.com' => Http::response(['foo' => 'bar']), 'forge.laravel.com' => Http::response(status: 204), ]);
Now:
// Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' => 204, ]);
Added Request::fluent() method
Added a fluent() method for the HTTP Request class to allow convenient passing of input data:
/* @var Illuminate\Http\Request $request /$data = $request->fluent();
$data->title; $data->body; //
Code Compatibility with PHP 8.4
Added code compatibility with PHP 8.4 for Laravel 10.x and 11.x.