F
Filament15mo ago
fasna

Display a filter based on previously selected filter option

I have a table, where there is a user_id column, which will be referred to two tables, teachers and students. I have a flag column to identify the user_type. Based on the user_type, I'll fetch the user's data from the relevant table, Students or Teachers. The table and form were customized and worked as expected. I need to add the same for the filters, where the user can choose the user_type first and based on that I need to display the Select filter option with the relevant usernames. How we can achieve this in filament, is it possible to do that?
2 Replies
Patrick Boivin
Patrick Boivin15mo ago
Sounds like a standard polymorphic relationship, maybe this can help: https://laravel.com/docs/10.x/eloquent-relationships#polymorphic-relationships For the dynamic options, I think you can access the tableFilters property on the page component:
Tables\Filters\SelectFilter::make('my_filter')
->options(function ($livewire) {
if ($livewire->tableFilters['other_filter']['value'] === 'foo') {
// return some options
}

// return other options
}),
Tables\Filters\SelectFilter::make('my_filter')
->options(function ($livewire) {
if ($livewire->tableFilters['other_filter']['value'] === 'foo') {
// return some options
}

// return other options
}),
fasna
fasnaOP15mo ago
Thank you, I'll check on this
Want results from more Discord servers?
Add your server