Select Filter for Enums
Is there a way to filter my AppointmentStatusEnums so it will only show Pending, Approved and Completed?
7 Replies
If your model has the appropriate cast for the enum, this should just work. What exactly is the issue you’re encountering?
no issue
Currently, It displays all seven statuses, but I want it to show only the statuses 'Pending,' 'Approved,' and 'Completed'.
You would need to manually set the options as an array of those enum values then.
I have an appended field that returns an Enum in my Model. The SelectFilter doesn't work on those cases. Is there a different way to filter appended fields?
Maybe you could implement it like this:
->options(collect(Status::cases())->where('name', '!=', 'IN_PROCESS')->pluck('name', 'value')->toArray()),
and of course, you can use whereIn()
as well.or explore this pos : https://laravel-news.com/laravel-10-46-0
Laravel News
Increment a Rate Limiter by a Custom Amount in Laravel 10.46 - Lara...
The Laravel team released v10.46 this week with new Enum validation methods, incrementing a rate limiter by a custom amount, Conditionable Enum validation rules, and more.
@NothingToSay in addition to customising a
SelectFilter
, when using Enums on a relationship, the default SelectFilter won't work. Filament tries to use the Enum in the where
clause in Eloquent as a string. So, in order to use the Enum in a relationship, you need to build your own, just using ->options()
:
Thought it would be nice to share this solution somewhere, since I had this issue in the last 2 hours...