Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[11.x] Added new Eloquent methods: whereDoesntHaveRelation, whereMorphDoesntHaveRelation and their variants with OR #53996

Open
wants to merge 1 commit into
base: 11.x
Choose a base branch
from

Conversation

andrey-helldar
Copy link
Contributor

@andrey-helldar andrey-helldar commented Dec 21, 2024

Laravel offers to simplify relation queries using the whereRelation and whereMorphRelation methods, but it doesn't have opposite methods. This PR adds them:

// Before
User::whereDoesntHave('comments', function ($query) {
    $query->where('created_at', '>', now()->subDay());
})->get();

// After
User::whereDoesntHaveRelation(
    'comments', 'created_at', '>', now()->subDay()
)->get();

User::whereDoesntHaveRelation(
    'comments', 'is_approved', false
)->get();
// 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();

…HaveRelation`, `whereMorphDoesntHaveRelation` and `orWhereMorphDoesntHaveRelation`
@andrey-helldar andrey-helldar changed the title Added new Eloquent methods: whereDoesntHaveRelation, orWhereDoesntHaveRelation, whereMorphDoesntHaveRelation and orWhereMorphDoesntHaveRelation [11.x] Added new Eloquent methods: whereDoesntHaveRelation and whereMorphDoesntHaveRelation Dec 21, 2024
@andrey-helldar andrey-helldar changed the title [11.x] Added new Eloquent methods: whereDoesntHaveRelation and whereMorphDoesntHaveRelation [11.x] Added new Eloquent methods: whereDoesntHaveRelation, whereMorphDoesntHaveRelation and their variants with OR Dec 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant