[Vuejs]-Get data to related Date in an array

1👍

assuming your done jobs have the value of ok from data column and key status.

you can do all the calculation in your query.

e.i this uses now function which uses carbon date

$fromDate = now()->subDays(11); // past 11 days from current date
$toDate = now(); 

return Jobs::selectRaw('Date(created_at) as date') // select date format Y-m-d
    ->selectRaw('count(created_at) AS allJobs')   //count result based on grouping
    ->selectRaw("Sum(CASE WHEN json_unquote(json_extract(`data`, '$.status')) = 'ok' THEN 1 ELSE 0 END) AS doneJobs") // sum all result that has value of data->status = ok
    ->whereBetween('created_at', [$fromDate, $toDate] ) //filter created_at from  the past 11 days up to current date
    ->groupBy('date') // group the result by date
    ->get();
👤silver

Leave a comment