F
Filament10mo ago
morty

Is this the proper way to have an "Include records" filter from a table with a modified query?

I have a filter like below and it's off by default so only active records are showing. Is this how I should be including inactive as well with a filter?
return $table
->filters([
Filter::make('inactive_flag')
->label('Include inactive')
->toggle()
->baseQuery(fn (Builder $query): Builder => $query->orWhere('inactive_flag', '=', 'Y')),
])
->modifyQueryUsing(fn (Builder $query): Builder => $query->where('inactive_flag', '!=', 'Y'))
return $table
->filters([
Filter::make('inactive_flag')
->label('Include inactive')
->toggle()
->baseQuery(fn (Builder $query): Builder => $query->orWhere('inactive_flag', '=', 'Y')),
])
->modifyQueryUsing(fn (Builder $query): Builder => $query->where('inactive_flag', '!=', 'Y'))
No description
Solution:
Never mind, I ended up going with a ternary instead. ```php TernaryFilter::make('inactive_flag') ->label('Status')...
No description
Jump to solution
1 Reply
Solution
morty
morty10mo ago
Never mind, I ended up going with a ternary instead.
TernaryFilter::make('inactive_flag')
->label('Status')
->placeholder('All')
->trueLabel('Active')
->falseLabel('Inactive')
->queries(
true: fn (Builder $query): Builder => $query->where('inactive_flag', '!=', 'Y'),
false: fn (Builder $query): Builder => $query->where('inactive_flag', '=', 'Y'),
),
TernaryFilter::make('inactive_flag')
->label('Status')
->placeholder('All')
->trueLabel('Active')
->falseLabel('Inactive')
->queries(
true: fn (Builder $query): Builder => $query->where('inactive_flag', '!=', 'Y'),
false: fn (Builder $query): Builder => $query->where('inactive_flag', '=', 'Y'),
),
No description
Want results from more Discord servers?
Add your server