filtered colum value
I have table like this. I implement tahun and bulan filter but the timelines_rencana_count, timelines_realisasi_count did't work. What i miss?
Solution:Jump to solution
Solved.
need to implement modifyqueryusing
->modifyQueryUsing(function (Builder $query, $livewire) {...
1 Reply
Solution
Solved.
need to implement modifyqueryusing
->modifyQueryUsing(function (Builder $query, $livewire) {
$filter = @$livewire->tableFilters['Periode'];
if (!isset($filter['tahun'], $filter['bulan'])) {
return $query;
}
$date = Carbon::createFromFormat('Y-m-d', "{$filter['tahun']}-{$filter['bulan']}-01");
$startOfMonth = $date->startOfMonth();
$endOfMonth = $date->copy()->endOfMonth();
return $query->whereHas('timelinesRencana', function ($subQuery) use ($startOfMonth, $endOfMonth) {
$subQuery->whereBetween('date', [$startOfMonth, $endOfMonth]);
})->withCount([
'timelinesRencana' => function ($subQuery) use ($startOfMonth, $endOfMonth) {
$subQuery->whereBetween('date', [$startOfMonth, $endOfMonth]);
},
'timelinesRealisasi' => function ($subQuery) use ($startOfMonth, $endOfMonth) {
$subQuery->whereBetween('date', [$startOfMonth, $endOfMonth]);
}
]);
})