Live select update issue

Hey! In one of the use cases, I have two multi select fields carBrands and 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
})
2 Replies
faroukb
faroukbOP3mo ago
Note: I just tried to pull these fields outside of the callback, instead of conditionally rendering them, render them all the time but hide them instead, and now the select seem to work, am I missing something? please let me know!
JJSanders
JJSanders3mo ago
Interesting I just ran into the same issue I think, gonna follow this post.

Did you find this page helpful?