-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
orWherePivot issue #29741
Comments
@staudenmeir do you know of any changes to this method? |
I'll take a look if we can make it work with closures. You can use the "normal" $user->BelongsToMany()->where(function ($query) {
$query->where('pivot_table.pivot', 0)->orWhere('pivot_table.another', 0);
})->get() The downside here is that |
I managed to use orWherePivot by adding the user_id manually:
|
I don't see a feasible way to make closures work. |
Probably a no fix, sorry. |
Description:
I am trying to use orWherePivot on a BelongsToMany relationship. When I use it per user, it cancels the filtration of user_id and it's applied to the global query so it returns all the records instead of only per user, when I try to enclose it in where closure scope, it throws
Call to undefined method Illuminate\Database\Eloquent\Builder::orWherePivot()
which makes it also applied to the global query.Is that a normal behavior? How can I use it only per user scope?
Steps To Reproduce:
The following returns all records not only per user
$user->BelongsToMany() ->wherePivot('pivot', 0) ->orWherePivot('another', 0)->get()
And the following throws the mentioned error
$user->BelongsToMany() ->where(function($query) { $query->wherePivot('pivot', 0) ->orWherePivot('another', 0); })->get()
The text was updated successfully, but these errors were encountered: