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

[12.x] Changed whereRelation and related function to work with only two params when the … #54975

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

Conversation

habibendris
Copy link
Contributor

@habibendris habibendris commented Mar 11, 2025

The Eloquent whereRelation accepts 4 parameters in total $relation, $column, $operator = null, $value = null

If the $column parameter is not a \Closure we should be able to use a syntax like
where clause.

If either of $column and $operator value is not null the addDotNotationToWhereRelation function
skips everything.

In where clause we can use something like this

    $posts = Post::query()
        ->where('user_id', Auth::id());
        ->where('user_id', '!=', $request->user_id);

So whenever we want to query we have to use the whereRelation as follows.

$posts = Post::query()
    ->whereRelation('comments', 'user_id', Auth::id())
    ->get()

We always have to use atleast 3 parameters.
This pull request allows us to only use 2 for this usecase.

What i want to do is the whereRelation and other related relation function
to act as the where clause.

    $posts = Post::query()
        ->whereRelation('comments', 'user_id', Auth::id());
        ->whereRelation('comments', 'user_id', '!=', $request->user_id);

    $posts = Post::query()
        ->whereRelation('comments.user_id', Auth::id());
        ->whereRelation('comments', 'user_id', '!=', $request->user_id);

This commit doesnt break any existing changes because i have written integration testing.
But if we want it to fully replace the previous method we can change the code to accomodate those things.

…`$column` IS NOT instance of `\Closure`, `$operator` is NULL and `$value` IS NULL
@habibendris habibendris changed the title [12.x] Changed whereRelation to work with only two params when the … [12.x] Changed whereRelation and related function to work with only two params when the … Mar 11, 2025
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