© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•7mo ago•
3 replies
faroukb

Live select update issue

Hey!
In one of the use cases, I have two multi select fields
carBrands
carBrands
and
carModels
carModels


Forms\Components\Select::make('carBrands')
    ->live()
    ->relationship(
       name: 'carBrands',
       titleAttribute: 'name',
       modifyQueryUsing: fn (Builder $query, Get $get) => $query->whereIn(
           'car_brands.id',
           ServiceStore::find($get('store_id'))?->carBrands()->pluck('car_brands.id')->all() ?? []
       )
    )
    ->multiple()
    ->preload()
    ->required(),

Forms\Components\Select::make('carModels')
    ->relationship(
        name: 'carModels',
        titleAttribute: 'name',
        modifyQueryUsing: fn (Builder $query, Get $get) => $query->whereIn(
           'car_brand_id',
           $get('carBrands') ?? [], // I also tried with ../carBrands
        )
    )
    ->multiple()
    ->preload()
    ->getSearchResultsUsing(
         fn (string $search, Get $get): array => CarModel::query()
            ->when($search, static fn (Builder $query) => $query
                ->whereLike('name', "%{$search}%")
                ->orWhereLike('name', '%' . ucwords($search) . '%'))
            ->whereIn('car_brand_id', $get('carBrands')) // I also tried with ../carBrands
            ->limit(10)
            ->get()
            ->mapWithKeys(fn (CarModel $carModel) => [
                $carModel->id => $carModel->name,
            ])
            ->toArray(),
     )
     ->required(),
Forms\Components\Select::make('carBrands')
    ->live()
    ->relationship(
       name: 'carBrands',
       titleAttribute: 'name',
       modifyQueryUsing: fn (Builder $query, Get $get) => $query->whereIn(
           'car_brands.id',
           ServiceStore::find($get('store_id'))?->carBrands()->pluck('car_brands.id')->all() ?? []
       )
    )
    ->multiple()
    ->preload()
    ->required(),

Forms\Components\Select::make('carModels')
    ->relationship(
        name: 'carModels',
        titleAttribute: 'name',
        modifyQueryUsing: fn (Builder $query, Get $get) => $query->whereIn(
           'car_brand_id',
           $get('carBrands') ?? [], // I also tried with ../carBrands
        )
    )
    ->multiple()
    ->preload()
    ->getSearchResultsUsing(
         fn (string $search, Get $get): array => CarModel::query()
            ->when($search, static fn (Builder $query) => $query
                ->whereLike('name', "%{$search}%")
                ->orWhereLike('name', '%' . ucwords($search) . '%'))
            ->whereIn('car_brand_id', $get('carBrands')) // I also tried with ../carBrands
            ->limit(10)
            ->get()
            ->mapWithKeys(fn (CarModel $carModel) => [
                $carModel->id => $carModel->name,
            ])
            ->toArray(),
     )
     ->required(),


These fields are wrapped within a section component

Forms\Components\Select::make('store_id')
    ->relationship(
      name: 'serviceStore',
      titleAttribute: 'name',
    )
    ->live()
    ->preload()
    ->searchable(),

Forms\Components\Section::make(__('Details'))
    ->schema(function (Get $get): array {
      ... // Depending on store type return the correct list of components 
})
Forms\Components\Select::make('store_id')
    ->relationship(
      name: 'serviceStore',
      titleAttribute: 'name',
    )
    ->live()
    ->preload()
    ->searchable(),

Forms\Components\Section::make(__('Details'))
    ->schema(function (Get $get): array {
      ... // Depending on store type return the correct list of components 
})
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Select live update problem
FilamentFFilament / ❓┊help
14mo ago
Update select with live API data
FilamentFFilament / ❓┊help
2y ago
Live update
FilamentFFilament / ❓┊help
3y ago
Richeditor live update
FilamentFFilament / ❓┊help
9mo ago