This week, the Laravel team released v11.34, with a
Request::fluent()
method, a Number
spellOrdinal()
helper, conditional route definitions,
shorthand fakes for HTTP responses, and more.
Spell ordinals as words
Joel Stein contributed the spellOrdinal()
to the Number
helper to spell ordinals as words:
'The ' . Number::spellOrdinal(40) . ' president of the United States is Ronald Reagan';
See Pull Request #53661 for more details.
Add the Conditional trait to routes
@Boorinio contributed the Conditional
trait to the Route
class, which allows developers 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());
});
See Pull Request #53654 for more details.
Shorthands for fake HTTP responses
Jason McCreary contributed shorthands when faking HTTP responses. Before v11.34 shorthand arrays were possible, however, this PR adds strings for the response body or an integer for the status code:
// Before
Http::fake([
'google.com' => Http::response('Hello World'),
'github.com' => Http::response(['foo' => 'bar']),
'forge.laravel.com' => Http::response(status: 204),
]);
// After
Http::fake([
'google.com' => 'Hello World',
'github.com' => ['foo' => 'bar'],
'forge.laravel.com' => 204,
]);
See Pull Request #53663 for more details.
Add Request::fluent()
Method
Steve Bauman contributed a fluent()
method to the HTTP Request class which enables being able to
transport input data fluently:
/** @var Illuminate\Http\Request $request */
$data = $request->fluent();
$data->title;
$data->body;
// etc.
See Pull Request #53662 for more details.
PHP 8.4 code compatibility
Mior Muhammad Zaki contributed PHP 8.4 code compatability for Laravel 10.x and well as v11.x during this release:
Release notes
You can see the complete list of new features and updates below and the diff between 11.33.0 and 11.34.0 on GitHub. The following release notes are directly from the changelog:
v11.34.0
- [10.x] Fix append and prepend batch to chain by @Bencute in https://github.com/laravel/framework/pull/53455
- [11.x] Allow
BackedEnum
when usingfromRoute()
inMakesHttpRequests
by @wietsewarendorff in https://github.com/laravel/framework/pull/53593 - [11.x] Test Improvements by @crynobone in https://github.com/laravel/framework/pull/53586
- [11.x] Move
$ownerKey
check fornull
toMorphTo
asBelongsTo
relationship will always return astring
by @crynobone in https://github.com/laravel/framework/pull/53592 - Unset eloquent model's cached cast attribute by @adamthehutt in https://github.com/laravel/framework/pull/53583
- [11.x] Add non-static JsonResource wrapping by @SanderMuller in https://github.com/laravel/framework/pull/53543
- [10.x] PHP 8.4 Code Compatibility by @crynobone in https://github.com/laravel/framework/pull/53612
- Add assertCount() for fake storage by @ahmadreza1383 in https://github.com/laravel/framework/pull/53620
- Fix Paginator __construct parameter typehint for phpstan by @Afrowson in https://github.com/laravel/framework/pull/53615
- [11.x] Add generics for Arr::last() by @talkinnl in https://github.com/laravel/framework/pull/53619
- Add typed closure to bootstrappers in console application by @MatusBoa in https://github.com/laravel/framework/pull/53613
- refactor: Some minor performance & readability enhancements by @dshafik in https://github.com/laravel/framework/pull/53596
- [11.x] Improve doc blocks for interacting with enum inputs by @axlon in https://github.com/laravel/framework/pull/53625
- [11.x] Skip object construction if no rebound callbacks are set by @axlon in https://github.com/laravel/framework/pull/53502
- Make the bearerToken method case-insensitive by @samtlewis in https://github.com/laravel/framework/pull/53627
- [11.x] Fix attribute inheritance for nested scheduled groups by @istiak-tridip in https://github.com/laravel/framework/pull/53626
- [11.x] Supports PHP 8.4 by @crynobone in https://github.com/laravel/framework/pull/53468
- ☁️ by @taylorotwell in https://github.com/laravel/framework/pull/53623
- [11.x] Fix typo in docblock by @stancl in https://github.com/laravel/framework/pull/53636
- Add Number::spellOrdinal() to spell ordinals as words. by @joelstein in https://github.com/laravel/framework/pull/53661
- [11.x] Add PausePrompt fallback by @jwpage in https://github.com/laravel/framework/pull/53660
- [11.x] Fix
SyntaxError
on Vite prefetch with empty assets by @jnoordsij in https://github.com/laravel/framework/pull/53659 - [11.x] Improved
class-string
types by @timacdonald in https://github.com/laravel/framework/pull/53657 - [11.x] Use
never
type for methods that always throws by @tamiroh in https://github.com/laravel/framework/pull/53643 - [11.x] Adds conditional to routes by @Boorinio in https://github.com/laravel/framework/pull/53654
- [11.x] Make
withoutDefer
also return$this
by @tamiroh in https://github.com/laravel/framework/pull/53644 - Add shorthands for fake HTTP responses by @jasonmccreary in https://github.com/laravel/framework/pull/53663
- Use the environment method instead of the isLocal method by @NaokiTsuchiya in https://github.com/laravel/framework/pull/53638
- [11.x] Fix: Ensure generated policies return boolean values by @Aluisio-Pires in https://github.com/laravel/framework/pull/53632
- Bus assertempty by @jasonmccreary in https://github.com/laravel/framework/pull/53664
- [11.x] Improve schedule group behaviors by @istiak-tridip in https://github.com/laravel/framework/pull/53641
- [11.x] Add
Request::fluent
method by @stevebauman in https://github.com/laravel/framework/pull/53662 - [11.x] Support named in-memory SQLite connections by @stancl in https://github.com/laravel/framework/pull/53635
- event name & listener callback types by @rudiedirkx in https://github.com/laravel/framework/pull/53642
- Test cleanup from #53664 by @jasonmccreary in https://github.com/laravel/framework/pull/53672
- [11.x] Fix: Prevent invalid AWS credentials options being created by @robchett in https://github.com/laravel/framework/pull/53633
- [11.x] Expand
Support\Fluent
data access and transformation capabilities by @stevebauman in https://github.com/laravel/framework/pull/53665
The post Access Request Data Fluently in Laravel 11.34 appeared first on Laravel News.
Join the Laravel Newsletter to get all the latest Laravel articles like this directly in your inbox.
Read more https://laravel-news.com/laravel-11-34-0