Closed markplus closed 1 year ago
You can just add a conditional where clause in the query:
public function query(Ticket $model): QueryBuilder
{
return $model->newQuery()->when(request('year'), fn($q, $year) => $q->whereYear('field', $year));
}
I need to know if I can filter the data by year, I would like a table with only data from a given year in it, with serverside I don't know how to set this up, I usually create a $ticket2023 = Ticket::whereYear(' created_at', Carbon::now()->year(2023))->count(); and I see with foreach the values I want, but I would like to do it with a TicketsDataTable.php table but I still don't understand how to filter the data as I want, I would like to do something like this but I don't know how to do it. Where and how can I insert something like this to get the result I want?