Laravel. How to exclude rows where the value is equal to 0?
I am running a query and save the results in a file. The SELECT looks like this:
$providers = groups::select('groups.id', DB::raw('count(DISTINCT groups_selection_filter.objectFK) as providers_total'))
But there are clients where the COUNT of
providers_total is equal to zero. For instance:
1759 => array:5 [ "id" => 1759 "name" => "Test Client" "provider_count" => 0 "sport_count" => 1 "sport_name" => "Soccer" ]
I need to remove such clients from the returned results. Tried with whereNot and HAVING
->havingRaw(DB::raw('count(DISTINCT groups_selection_filter.objectFK)', '!==', 0))
But so far without success…any ideas?
Solution – 1
I managed to get the results I wanted like this: After the query using
$only_ids = array_keys($compliance);
And later in my 2nd and 3rd query using the where in like that: