F
Filamentβ€’10mo ago
Mark Chaney

Custom Filter Default

Im using an enum for this filter. The options are working great and filtering correctly, but I cant seem to set a default.
Tables\Filters\Filter::make('property_type')
->default(function () use ($rfta) {
return [
$rfta->property->type->value,
];
})
->form([
Forms\Components\Section::make('Property Type')
->schema([
Forms\Components\Select::make('type')
->hiddenLabel()
->multiple()
->placeholder('All Property Types')
->options(PropertyType::class),
]),
])
->query(function ($query, $data) {
return $query->when($data['type'], function ($query, $value) {
return $query->whereHas('property', function ($query) use ($value) {
$query->whereIn('type', $value);
});
});
}),
Tables\Filters\Filter::make('property_type')
->default(function () use ($rfta) {
return [
$rfta->property->type->value,
];
})
->form([
Forms\Components\Section::make('Property Type')
->schema([
Forms\Components\Select::make('type')
->hiddenLabel()
->multiple()
->placeholder('All Property Types')
->options(PropertyType::class),
]),
])
->query(function ($query, $data) {
return $query->when($data['type'], function ($query, $value) {
return $query->whereHas('property', function ($query) use ($value) {
$query->whereIn('type', $value);
});
});
}),
Any advice?
Solution:
did you try to set the default value on the select
Jump to solution
5 Replies
Solution
mvenghaus
mvenghausβ€’10mo ago
did you try to set the default value on the select
mvenghaus
mvenghausβ€’10mo ago
i had also some problems when using filter > select .. so i change to SelectFilter πŸ™‚ SelectFilter::make('filter') ->default('default')
Mark Chaney
Mark ChaneyOPβ€’10mo ago
lol, that did work. sheesh.
Mark Chaney
Mark ChaneyOPβ€’10mo ago
lol, i should go to bed. 230am. Not making wise choices. Thanks!
mvenghaus
mvenghausβ€’10mo ago
it's 8:30 πŸ˜‰
Want results from more Discord servers?
Add your server