F
Filamentβ€’9mo ago
Jordy

Morph col filter

how does one go about filtering a morph col? I can assign a user or a team to a task.. want a searchable select filter for it but I cant figure out how to do it I was thinking of making 2 seperate ones (first select if you want to filter a User or Team, (assigned_type) when filled in (assigned_id) appears with Users or Teams its how I do create/update, but you cannot depend/have reactive filter inputs it seems) Is there an easier way to achieve what I want?
Solution:
Don't use a SelectFilter, but a Custom filter with a form
Jump to solution
14 Replies
Dennis Koch
Dennis Kochβ€’9mo ago
but you cannot depend/have reactive filter inputs it seems)
Did you try it? Not sure whether it works, but don't know why it shouldn't be possible with a filter form?
I was thinking of making 2 seperate ones (first select if you want to filter a User or Team, (assigned_type)
Sounds good to me.
Jordy
Jordyβ€’9mo ago
I dont know how to retrieve the value from the first filter in the second one.. $get does not work as it does with form inputs
SelectFilter::make('assigned_type')
->label(__('Toegewezen aan type'))
->options([
User::class => __('Gebruiker'),
Team::class => __('Team'),
])
->default(User::class)
->searchable(),

SelectFilter::make('assigned_id')
->label(__('Toegewezen aan'))
->options(fn() =>
//get value from assigned_type filter
)
->searchable(),
SelectFilter::make('assigned_type')
->label(__('Toegewezen aan type'))
->options([
User::class => __('Gebruiker'),
Team::class => __('Team'),
])
->default(User::class)
->searchable(),

SelectFilter::make('assigned_id')
->label(__('Toegewezen aan'))
->options(fn() =>
//get value from assigned_type filter
)
->searchable(),
Solution
Dennis Koch
Dennis Kochβ€’9mo ago
Don't use a SelectFilter, but a Custom filter with a form
Jordy
Jordyβ€’9mo ago
so one filter with the two fields?
Dennis Koch
Dennis Kochβ€’9mo ago
Yep It's one Filter anyway, right?
Jordy
Jordyβ€’9mo ago
yes just making sure I understood right haha.. I shall take a look, cheers :) got it working, thanks Dennis
Jordy
Jordyβ€’9mo ago
seems there is also a built in way.. you shouldve known this. @Dennis Koch 😜 https://filamentphp.com/docs/3.x/forms/fields/select#handling-morphto-relationships (in case of future readers)
Dennis Koch
Dennis Kochβ€’9mo ago
Actually I wanted to share this, then read that you want a Filter and then didn't forgot to mention it with the ->form() solution πŸ˜…
Jordy
Jordyβ€’9mo ago
all good haha, got pointed to it during code review :)
Dennis Koch
Dennis Kochβ€’9mo ago
Just point it to the junior devs
Jordy
Jordyβ€’9mo ago
I am the junior dev πŸ’€
Dennis Koch
Dennis Kochβ€’9mo ago
I meant me πŸ˜…
Jordy
Jordyβ€’9mo ago
ahh lol
Houssem
Houssemβ€’8mo ago
';/ \