Table Select Filters

On a table I have the following filters:

When I select a Network, I can only see the switches associated with this network when I refresh the page.

Is there a way to "live" update the filters?

Here is the code for the filters...

SelectFilter::make('network_id')
                    ->label('Network')
                    ->multiple()
                    ->options(fn() => ModelName::pluck('name', 'id')->map(fn($network) => ucfirst($network))->sort()->toArray())
                    ->placeholder('Select Network'),

                SelectFilter::make('switch.name')
                    ->label('Switch Name')
                    ->multiple()
                    ->searchable()
                    ->preload()
                    ->optionsLimit(1000)
                    ->options(function () use ($table) {
                        $filter = $table->getFilter('network_id');
                        $selectedNetworkIds = $filter?->getState()['values'] ?? [];

                        $query = ModelName::query();

                        if (!empty($selectedNetworkIds)) {
                            $query->whereIn('network_id', $selectedNetworkIds);
                        }

                        return $query->pluck('name', 'name')->sort();
                    })
                    ->placeholder('Select Switch Name')
                    ->query(function (Builder $query, array $state) {
                        return $state['values'] ? $query->filterBySwitchName($state['values']) : null;
                    }),
image.png
Was this page helpful?