I have a Shop
model that can has three relationships: Specials
, Discounts
and ThrowOuts
. I want to select all Shop
s that have data in any one of those three relationships, but mask the ones that don't have any at all.
I also want to limit the search results based on properties of the Shop
itself:
Shop::where('state', $state)
->whereHas('Specials')
->whereHas('Discounts ')
->whereHas('ThrowOuts')
This query requires that all the relationships have data - none can be blank
Shop::where('state', $state)
->orWhereHas('Specials')
->orWhereHas('Discounts ')
->orWhereHas('ThrowOuts')
Using orWhereHas
returns all of the shops that have any data in those relationships regardless of the first "where" so I get shops from all over the country as well.