$select = DB::raw(
'COUNT(*) AS total
, COUNT(CASE status WHEN "paid" THEN 1 ELSE NULL END) AS paid
');
$metrics = DB::table('subscriptions')->select($select);
@ovvessem Nice! Now I get both count returned right? I actually want a list with all subscriptions. And a count of the subscriptions with a paid status of 1.
@RonaldGJ Yes, with the raw query you would get the total counts for both conditions. If you want the list in combination with the total count then the raw statement is not what you are looking for.
More suitable approach would be the suggestion @Drfraker gave. To confirm it will not run a new query against the database. If you are curious which query's are executed you could use of one of the following packages:
@RonaldGJ That is correct, it will not run another query. Once you call the get() method on query you get an eloquent collection. So manipulation of that data is not hitting the database anymore.