List filter with 3 states
0
If you need to filter a list with 3 states, you can use the "switch" filter type as below:
monthFilter:
label: Previous / Current Month
type: switch
default: 0
scope: currentOrPreviousMonth
In your model, add this scope method:
public function scopeCurrentOrPreviousMonth($query, $state)
{
return match ($state) {
// unfiltered query
"0" => $query,
// filter for state 1
"1" => $query->previousMonth(),
// filter for state 2
"2" => $query->currentMonth(),
};
}
There are no comments yet
Be the first one to comment