Chartjs-Cannot view graph using toArray()

1👍

count() is aggregate method and directly return the number of rows you are querying.

DiraChatLog::where('status','=','Match')->count();

// which the same as

DiraChatLog::where('status','=','Match')->selectRaw('count(1) as cnt')->first()->cnt;

Assuming you are querying the data of number of rows per group, and sort by date in ascending order:

$match = DiraChatLog::where('status','=','Match')
    ->selectRaw('DATE(created_at) as date, COUNT(1) as cnt') // created_at here is datetime format, only need the date portion using `DATE` function
    ->orderBy("date")
    ->groupBy("date")
    ->get() // return result set (collection) from query builder
    ->pluck('cnt') // only need the cnt column
    ->values() // array_values
    ->all(); // convert collection to array

Leave a comment