Currently I have this whereHas in a collection of my model:
$query = self::whereHas('club', function($q) use ($search)
{
$q->whereHas('owner', function($q) use ($search)
{
$q->where('name', 'LIKE', '%'. $search .'%');
});
});
I was under the impression the code above could be as such:
$query = self::whereHas('club.owner', function($q) use ($search)
{
$q->where('name', 'LIKE', '%'. $search .'%');
});
I'm aware this is already a lot of power, but even then, if I have a nested relationship 5 levels deep, things will get ugly.
Update:
As stated in the comments, I ended up not making my question clear, I apologize.
I will try to use a simple example, consider $owner->club->membership->product->package
, now from owners I want to search a certain package, it would be something like this:
$query = self::whereHas('club', function($q) use ($search)
{
$q->whereHas('membership', function($q) use ($search)
{
$q->whereHas('product', function($q) use ($search)
{
$q->whereHas('package', function($q) use ($search)
{
$q->where('alias', 'LIKE', '%'. $search .'%');
});//package
});//product
});//membership
});//club
Is this correct? Is there a shortcut?
See Question&Answers more detail:os