-
Notifications
You must be signed in to change notification settings - Fork 11.3k
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
[13.x] Fix Eloquent Builder instance in relation class inside closure #53551
base: master
Are you sure you want to change the base?
[13.x] Fix Eloquent Builder instance in relation class inside closure #53551
Conversation
Marking as draft since tests are failing. |
@Sajid-al-islam I was looking at your PR, the test fails because the withTrashed function in MorphTo thinks a query-builder for the model is passed, but in reality, the relation is passed. The argument in the callback I think this might be a way to proceed, but I think the macro-check needs to be done differently. The 'withoutTrashed' and 'onlyTrashed' in the same class use the same logic. Because this changes the real type of the argument in the callback from |
@rikvdh thanks, I will look into it |
Fixes #53292
Description
When using the
when()
method on aBelongsToMany
relationship, the query builder instance was being returned instead of the relationship instance, preventing the use of relationship-specific methods likewherePivot
.This PR fixes the issue by maintaining the relationship instance within the
when()
method specifically forBelongsToMany
relationships while preserving existing behavior for other relationship types.Example Usage