Live select update issue
Hey!
In one of the use cases, I have two multi select fields
These fields are wrapped within a section component
In one of the use cases, I have two multi select fields
carBrandscarBrands and carModelscarModels 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
})