Replies: 1 comment
-
I don't think it will be what you want anyway, join the relation and add the column you want to sort in the select, this way you can sort by it. If it is what you want good, cause the problem is not there ( maybe ). Are you sure you want the condition on the ->with() and not on the ->whereHas()? Do you really want rows where the condition doesn't apply? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
It might be that I'm just overlooking the obvious, but there (as far as I can tell) doesn't seem to be a way to add multiple callbacks when eager loading relationships.
Example:
Now you might think, just combine it into one callback. But my specific use case comes from custom Sort and Filter classes I have made with Spatie's Query builder package.
You might create them like so:
The above results in that only the callback of the last one added gets executed.
Now I can check within my custom classes if a prior eager loading relationship was already set, and then append the callback's I need. But that feels a little dirty to me. Maybe I'm just overlooking the obvious.
Otherwise, a possible addition to the. Query builder of Laravel might be (just a concept):
Then you can specifically indicate that you want to append to existing callbacks. I could work on a PR if that is something that is useful. But again, probably overlooking something. 😅
Looking forward to any insights here!
Beta Was this translation helpful? Give feedback.
All reactions