© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•16mo ago•
2 replies
Neamix

Dynamic Filter

I want to create dynamic filter like step filter example i have table pet and each pet have type and each type contain a group of species so what i want to do here to allow user to choose the type first then the species appear to him i tried that concept
->filters([
                SelectFilter::make('pet_type_id')
                    ->label('نوع الحيوان')
                    ->query(fn($data) => Session::put('pet.pet_type_id',$data['value'] ?? null))
                    ->options(PetType::pluck('name_ar','id')->toArray()),

                SelectFilter::make('pet_specie_id')
                    ->options(function() {
                        $selectedPetType = Session::get('pet.pet_type_id');
                        dump($selectedPetType);
                        if ($selectedPetType)
                            return PetSpecie::where('pet_type_id',$selectedPetType)->pluck('specie_ar','id')->toArray();
                        else 
                            return PetSpecie::pluck('specie_ar','id')->toArray();
                    })
                    ->label('فصيلة الحيوان'),

                SelectFilter::make('pet_color_id')
                    ->label('لون الحيوان')
                    ->options(PetColor::pluck('color_ar', 'id')->toArray()),
            ])
->filters([
                SelectFilter::make('pet_type_id')
                    ->label('نوع الحيوان')
                    ->query(fn($data) => Session::put('pet.pet_type_id',$data['value'] ?? null))
                    ->options(PetType::pluck('name_ar','id')->toArray()),

                SelectFilter::make('pet_specie_id')
                    ->options(function() {
                        $selectedPetType = Session::get('pet.pet_type_id');
                        dump($selectedPetType);
                        if ($selectedPetType)
                            return PetSpecie::where('pet_type_id',$selectedPetType)->pluck('specie_ar','id')->toArray();
                        else 
                            return PetSpecie::pluck('specie_ar','id')->toArray();
                    })
                    ->label('فصيلة الحيوان'),

                SelectFilter::make('pet_color_id')
                    ->label('لون الحيوان')
                    ->options(PetColor::pluck('color_ar', 'id')->toArray()),
            ])


the only reason that i used query() because it was the only thing that worked as a callback function and this approche worked but the problem is that he get the prev type as example if i have type 0 default ,1 ,2 if i changed type from 0 to 1 it will show species of 0 if i changed 1 to 2 it will show species of 1 and so one
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

dynamic table filter label
FilamentFFilament / ❓┊help
3y ago
Dynamic Default Chart Filter
FilamentFFilament / ❓┊help
3y ago
Dynamic getTableQuery on Toggle Filter
FilamentFFilament / ❓┊help
3y ago
Filter test FAILED `filterTable` doesn't work
FilamentFFilament / ❓┊help
13mo ago