I guess query returns null if you dont get rows so try something like that :
public function scopeGetCountForAllCategoriesForLocation($query)
{
$q = $query->whereActive(1)->count() ;
return $q === null ? 0 : $q;
}
Hi, I have a problem with count() in model scope. When it has any count above 0 to return then is ok, but when count() is equal to 0 it returns Builder collection instead of "0". When I call count() method in controller then it works, but I would like to clear that part and keep it in model scope. Is here any "hack" for that ?
public function scopeGetCountForAllCategoriesForLocation($query)
{
return $query->where('active', 1)->count() ;
}
Please or to participate in this conversation.