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


Click the link to join the registration on WhatsApp: https://chat.whatsapp.com/KThkuZlWaTcCu3iJHGBmLM


Click the link to join the registration on WhatsApp: https://chat.whatsapp.com/KThkuZlWaTcCu3iJHGBmLM


Click the link to join the registration on WhatsApp: https://chat.whatsapp.com/KThkuZlWaTcCu3iJHGBmLM

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

Keep advertising to get more people

You could reach thousands of more people for every ₦1,000 you spend. https://doacweb.com/advertising

Adverts on doacWeb can be informative, educative or persuasive in nature.

doacWeb Ads is always directed at a broad audience (reaching thousands of people day by day), not few individuals — it deliver your advert to the target audience at the same time. Putting your offer in front of the right people — who have the money and interest in what you sell.

doacWeb Advertising gives you advantage as adverts passes through https://doacweb.com to the internet, reaching millions of people over the internet, and to grow your audience.

Grow your business, Be known, Boost your visibility, Drive engagements, Get new customers and Increase sales.

doacWeb acts as a global advertising media, to let people — individuals — and businesses, to promote and reach more interested people.

Get Started.

WhatsApp: 09031633831

Email: info@doacweb.com
Keep advertising to get more people

You could reach thousands of more people for every ₦1,000 you spend. https://doacweb.com/advertising

Adverts on doacWeb can be informative, educative or persuasive in nature.

doacWeb Ads is always directed at a broad audience (reaching thousands of people day by day), not few individuals — it deliver your advert to the target audience at the same time. Putting your offer in front of the right people — who have the money and interest in what you sell.

doacWeb Advertising gives you advantage as adverts passes through https://doacweb.com to the internet, reaching millions of people over the internet, and to grow your audience.

Grow your business, Be known, Boost your visibility, Drive engagements, Get new customers and Increase sales.

doacWeb acts as a global advertising media, to let people — individuals — and businesses, to promote and reach more interested people.

Get Started.

WhatsApp: 09031633831

Email: info@doacweb.com
Keep advertising to get more people

You could reach thousands of more people for every ₦1,000 you spend. https://doacweb.com/advertising

Adverts on doacWeb can be informative, educative or persuasive in nature.

doacWeb Ads is always directed at a broad audience (reaching thousands of people day by day), not few individuals — it deliver your advert to the target audience at the same time. Putting your offer in front of the right people — who have the money and interest in what you sell.

doacWeb Advertising gives you advantage as adverts passes through https://doacweb.com to the internet, reaching millions of people over the internet, and to grow your audience.

Grow your business, Be known, Boost your visibility, Drive engagements, Get new customers and Increase sales.

doacWeb acts as a global advertising media, to let people — individuals — and businesses, to promote and reach more interested people.

Get Started.

WhatsApp: 09031633831

Email: info@doacweb.com