Laravel Eloquent Count倍数

I currently have:

  $emails = Email::select('username', DB::raw('count(*) as total'))
        ->groupBy('username')
        ->get();

Returning:

     {'username' => 'example', 'total'=>'120' }

What I trying to do is to also get a count of a certain row value, where row value is equal to 1, to obtain:

      {'username' => 'example', 'total'=>'120', 'sent' => '23' }

Like a :

     DB::raw('count(sentitems) as sent WHERE sentitems = 1')

but of course it won't work this way .

If I understand you correctly, you mean something like this:

$emails = Email::select('username', DB::raw('count(*) as total'), DB::raw('count(case sentitems when 1 then 1 else null end) as sent')))
    ->groupBy('username')
    ->get();

What can the row value be if it isn't 1? If the only possible values are 0 and 1, you can simply use sum(sentitems). If other values are possible, you do sum(if(sentitems = 1, 1, 0))