You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This works fine, however the problem came when I needed to add more filtering logic specific to the Organisation resource. I noticed that any filter I would apply after the orWhereHas wouldn't take any effect on the result. For example if I need to get the last resource, this will still return the first resource. If I apply another where clause, this won't take any effect on the result it will only consider up to the orWhereHas method.
It finally worked as I intended when I had placed the whereHas method as the first filter and had orWhere method as the second filter, any other subsequent filter I applied after this specific order would take effect on the result like so:
This specific ordering of the whereHas method, is this how it is supposed to work? or i'm missing something for it to work the way i wanted it to while using the first way of things (disregarding order)?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Laravel 11.x
PHP 8.3
I recently had the need to query resources based on the following factors:
hasMany
relationship) which belongs to the authenticated user.So I used an
orWhereHas
method like so:This works fine, however the problem came when I needed to add more filtering logic specific to the
Organisation
resource. I noticed that any filter I would apply after theorWhereHas
wouldn't take any effect on the result. For example if I need to get the last resource, this will still return the first resource. If I apply another where clause, this won't take any effect on the result it will only consider up to theorWhereHas
method.It finally worked as I intended when I had placed the
whereHas
method as the first filter and hadorWhere
method as the second filter, any other subsequent filter I applied after this specific order would take effect on the result like so:This specific ordering of the
whereHas
method, is this how it is supposed to work? or i'm missing something for it to work the way i wanted it to while using the first way of things (disregarding order)?Beta Was this translation helpful? Give feedback.
All reactions