New Eloquent Relation Existence Methods in Laravel 11.37

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::whereDoe

New Eloquent Relation Existence Methods in Laravel 11.37

ARE YOU TIRED OF LOW SALES TODAY?

Connect to more customers on doacWeb

Post your business here..... from NGN1,000

WhatsApp: 09031633831

ARE YOU TIRED OF LOW SALES TODAY?

Connect to more customers on doacWeb

Post your business here..... from NGN1,000

WhatsApp: 09031633831

ARE YOU TIRED OF LOW SALES TODAY?

Connect to more customers on doacWeb

Post your business here..... from NGN1,000

WhatsApp: 09031633831

New Eloquent Relation Existence Methods in Laravel 11.37

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


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.

What's Your Reaction?

like

dislike

love

funny

angry

sad

wow