zouhair lyz
How to dynamically update Province select based on Region select in Filament Tables filter?
Hi everyone,
I’m using Filament Tables and have two dependent filters: Region and Province. I want the Province select options to update dynamically when a Region is selected, without refreshing the entire page.
Here’s my current setup:
php
Copier le code
->filters([
SelectFilter::make('region_id')
->label('Region')
->searchable()
->options(Region::pluck('name', 'id'))
->query(fn($query, $data) => $data ? $query->whereHas('province', fn($q) => $q->where('region_id', $data)) : null),
SelectFilter::make('province_id')
->label('Province')
->searchable()
->options(fn() => request()->input('tableFilters.region_id')
? Province::where('region_id', request()->input('tableFilters.region_id'))->pluck('name', 'id')->toArray()
: [])
->query(fn($query, $data) => $data ? $query->where('province_id', $data) : null),
])
The Province select doesn’t update after selecting a Region unless the page is refreshed.
Is there a way to dynamically update the Province options upon Region change, using a Filament-native approach or Livewire?
Thanks in advance!
15 replies