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. Any advice?
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);
});
});
}),