lundi 13 juillet 2020

Separate where condition for each selected count in laravel

In laravel I am trying to get multiple counts like

      $records=DB::table('my_table')
             ->select(DB::raw('COUNT(id) as record_count'),DB::raw('COUNT(id) as record_count_1 where status="done"'),DB::raw('COUNT(id) as record_count_2 where status="failed"'))
             ->where('record_date','>=','2020-07-12')
             ->where('sent_at','<=','2020-07-13')
             ->get();

So that I can get related values as

     pr($records[0]->record_count);
     pr($records[0]->record_count_1);
     pr($records[0]->record_count_2);

But there is syntax error. How can I do this in laravel framework? Thanks in advance.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire