Created
May 20, 2019 12:28
-
-
Save reinink/e3fa25eae14aab7d3301e4be5510f354 to your computer and use it in GitHub Desktop.
Getting table totals using Laravel Eloquent
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$totals = DB::table('subscribers') | |
->addSelect(DB::raw('count(*) as all')) | |
->addSelect(DB::raw("sum(case when status = 'confirmed' then 1 else 0 end) as confirmed")) | |
->addSelect(DB::raw("sum(case when status = 'unconfirmed' then 1 else 0 end) as unconfirmed")) | |
->addSelect(DB::raw("sum(case when status = 'cancelled' then 1 else 0 end) as cancelled")) | |
->addSelect(DB::raw("sum(case when status = 'bounced' then 1 else 0 end) as bounced")) | |
->addSelect(DB::raw("sum(case when status = 'inactive' then 1 else 0 end) as inactive")) | |
->get(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment