Yes it is
$categories = ProductCategory::whereHas('products', function ($query) {
$query->whereNotIn('type', ['service', 'misc']);
})->published()->get();
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Just curious if there are any other ways to get the same result for this query.
$categories = ProductCategory::whereHas('products', function($query) use($request) {
$query->whereNotIn('type', ['service', 'misc']);
})->published()->get();
Or This query :
$supports = Support::groupBy('support_status_id', '!=', 4 )->havingRaw('COUNT(*) > 1')->get();
Scope question? Is there a scope to return a count of all non closed status between support and support status tables.
scope_statuses >
1:pending
2:assigned
3:on hold
4:closed
Hi @madsynn
When working with scopes you are defining query constraints that are going to be applied on an Illuminate\Database\Eloquent\Builder instance ($query).
To be able to access model relationships you're expected to have an instance of the model, in your case App\Model\Support (which you don't when working with scopes).
On the other hand this should work:
public function scopeIsReturn($query)
{
return $query->whereHas('case_reason', function ($q) {
$q->where('id', 1);
});
}
This will return all "Support" records that have a corresponding "SupportCategory" with an ID of 1.
Of course it would be much easier to just query the foreign key of the support table:
public function scopeIsReturn($query)
{
return $query->where('case_reason_id', 1);
}
Please or to participate in this conversation.