t0berius
7 months ago

whereHas() relation

Posted 7 months ago by t0berius

I'm using this filter at the moment:

$product->whereHas('views', function ($query) {
    $query->groupBy('product_id');
});

The problem with this filter query is, all models with 0 views will be excluded. Is there some way to retrieve this models too? Otherwise they will be excluded totally. What way to choose so I can get the views for all "unviewed" entries too?

Please sign in or create an account to participate in this conversation.