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(),