I have a filament resource with a table. I want to change the table query based on the condition i.e. if there is a filter
->modifyQueryUsing(function (Builder $query){
if (tableFilter)
{
return $query->with('studentAcademics');
}
else
{
return $query->whereNull('id');
}
})
How can I check if there is an active table filter?
This solved my problem
->modifyQueryUsing(function (Builder $query, Table $table) {
$filters = $table->getFilters();
// Check if any filters are applied
$hasActiveFilters = collect($filters)
->some(function ($filter){
return $filter->getActiveCount() > 0;
});
if ($hasActiveFilters) {
// If filters are active, modify the query accordingly
return $query->with('studentAcademics');
} else {
// If no filters are active, apply a different query modification
return $query->whereNull('id');
}
})