Last week the Laravel team released v11.37, which includes new Eloquent relation methods, an option to ignore case with Str::is(), adding the Dumpable trait to a Uri instance, and more.
Add Dumpable Trait to Uri
Adrian Nürnberger added the Dumpable trait to the Uri class, which allows you to call dump() and dd() on a Uri instance. This allows you to dump at a certain point in the chain of your Uri instance, or dump and exit using dd():

Add "Ignore Case" Option to Str::is()
Steve Bauman contributed the ability to ignore case using the Str::is() method as well as a Stringable instance. This allows developers to remove strict-case comparison, similar to how Str::contains() works:

New Eloquent Relation Methods
Andrey Helldar contributed whereDoesntHaveRelation and whereDoesntHaveMorph relation method, which are the opposite of the existing relation existence queries.
whereDoesntHaveRelation examples:
// Before
User::whereDoesntHave('comments', function ($query) {
$query->where('created_at', '>', now()->subDay());
})->get();
// After
User::whereDoesntHaveRelation(
'comments', 'created_at', '>', now()->subDay()
)->get();
// Another example
User::whereDoesntHaveRelation(
'comments', 'is_approved', false
)->get();
whereMorphDoesntHaveRelation examples:
// Before
User::whereDoesntHaveMorph('comments', [Post::class, Video::class], function ($query) {
$query->where('created_at', '>', now()->subDay());
})->get();
// After
User::whereMorphDoesntHaveRelation(
'comments', [Post::class, Video::class], 'created_at', '>', now()->subDay()
)->get();
User::whereMorphDoesntHaveRelation(
'comments', [Post::class, Video::class], 'is_approved', false
)->get();
Add assertFailedWith to InteractsWithQueue Trait
Teddy Francfort contributed an assertFailedWith method to the InteractsWithQueue trait, which allows you to check a failure exception in a test:
use App\Jobs\ProcessPodcast;
use App\Exceptions\MyException;
$job = new ProcessPodcast()->withFakeQueueInteractions();
$job->assertFailedWith('whoops');
$job->assertFailedWith(MyException::class);
$job->assertFailedWith(new MyException);
$job->assertFailedWith(new MyException(message: 'whoops'));
$job->assertFailedWith(new MyException(message: 'whoops', code: 123));
Release notes
You can see the complete list of new features and updates below and the diff between 11.36.0 and 11.37.0 on GitHub. The following release notes are directly from the changelog:
v11.37.0
- [11.x] Update Collection::hasAny by @JeftaAtSiip in https://github.com/laravel/framework/pull/53963
- [11.x] Update DetectsLostConnections trait by @holgerk in https://github.com/laravel/framework/pull/53966
- Fix: (Queue Worker) firing the JobPopped event when $popCallbacks returns null by @rudenav in https://github.com/laravel/framework/pull/53962
- [11.x] Add
Dumpabletrait toUriby @nuernbergerA in https://github.com/laravel/framework/pull/53960 - Fix: Handle mixed-type values in compileInsert by @alipadron in https://github.com/laravel/framework/pull/53948
- [11.x] Add
$ignoreCaseoption toStr::isby @stevebauman in https://github.com/laravel/framework/pull/53981 - [11.x] Updates component dependencies by @crynobone in https://github.com/laravel/framework/pull/53975
- [11.x] Update Uri
withoutQuerymethod to accept string or array input by @1weiho in https://github.com/laravel/framework/pull/53973 - [11.x] Fix cached health endpoint not working when in maintenance mode by @crynobone in https://github.com/laravel/framework/pull/53974
- Add PHPDoc type hints by @shaedrich in https://github.com/laravel/framework/pull/53984
- [11.x] Allow passing bool to facade Http@preventStrayRequests() by @cosmastech in https://github.com/laravel/framework/pull/53992
- [11.x] Use Str::wrap() instead of nesting Str::start() inside Str::finish() by @shaedrich in https://github.com/laravel/framework/pull/53987
- Fix day range in docblock by @timacdonald in https://github.com/laravel/framework/pull/53985
- [11.x] Fixes
Illuminate\Http\Responseto output empty string if$contentis set tonullby @crynobone in https://github.com/laravel/framework/pull/53872 - [11.x] Fix/Improve Resend transport response handling by @markovic-nikola in https://github.com/laravel/framework/pull/54004
- [11.x] Update View::withErrors() docblock to reflect string parameter support by @cheack in https://github.com/laravel/framework/pull/54009
- 11.x improve resend transport response handling - fix by @markovic-nikola in https://github.com/laravel/framework/pull/54006
- [11.x] Added new Eloquent methods:
whereDoesntHaveRelation,whereMorphDoesntHaveRelationand their variants withORby @andrey-helldar in https://github.com/laravel/framework/pull/53996 - [11.x] Re-refresh the database if the
RefreshDatabasetransaction was committed by @SjorsO in https://github.com/laravel/framework/pull/53997 - [11.x] add assertFailedWith to InteractsWithQueue trait by @teddy-francfort in https://github.com/laravel/framework/pull/53980
- Quick doc fix by @mathiasgrimm in https://github.com/laravel/framework/pull/54040
- [11.x] Allow using
Illuminate\Support\Urion testing HTTP Requests by @crynobone in https://github.com/laravel/framework/pull/54038 - [11.x] Adding tests for Overlapping Routes by @mathiasgrimm in https://github.com/laravel/framework/pull/54050
- [11.x] adding tests for
null&*key given indata_getby @jwjenkin in https://github.com/laravel/framework/pull/54059
The post New Eloquent Relation Existence Methods in Laravel 11.37 appeared first on Laravel News.
Join the Laravel Newsletter to get all the latest Laravel articles like this directly in your inbox.
