State - City select fields

I have this code, got from the filament documentation
Select::make('state_id')
->searchable()
->label('Estado')
->native(false)
->preload()
->options(State::query()->pluck('name', 'id'))
->required(),
Select::make('city_id')
->label('Cidade')
->native(false)
->options(fn (Get $get): Collection => City::where('state_id', $get('state_id'))
->orderBy('name')
->pluck('name','id'))
->searchable()
->required(),
Select::make('state_id')
->searchable()
->label('Estado')
->native(false)
->preload()
->options(State::query()->pluck('name', 'id'))
->required(),
Select::make('city_id')
->label('Cidade')
->native(false)
->options(fn (Get $get): Collection => City::where('state_id', $get('state_id'))
->orderBy('name')
->pluck('name','id'))
->searchable()
->required(),
Honestly, it gets the job done, but the second select (which should return all cities from the selected state) I'm getting just a few cities, out of 150ish or more, is there a limitation related to searchable() or Select::class itself? is there a better option to this?
Solution:
```php Select::make('author_id') ->searchable() ->getSearchResultsUsing(fn (string $search): array => User::where('name', 'like', "%{$search}%")->limit(50)->pluck('name', 'id')->toArray()) ->getOptionLabelUsing(fn ($value): ?string => User::find($value)?->name),...
Jump to solution
3 Replies
tuto1902
tuto19026mo ago
I think when you make the field searchable, it does limit the number of results. I’ll go try to find out if there’s a way to configure it
Solution
Dan-webplusm
Dan-webplusm6mo ago
Select::make('author_id')
->searchable()
->getSearchResultsUsing(fn (string $search): array => User::where('name', 'like', "%{$search}%")->limit(50)->pluck('name', 'id')->toArray())
->getOptionLabelUsing(fn ($value): ?string => User::find($value)?->name),
Select::make('author_id')
->searchable()
->getSearchResultsUsing(fn (string $search): array => User::where('name', 'like', "%{$search}%")->limit(50)->pluck('name', 'id')->toArray())
->getOptionLabelUsing(fn ($value): ?string => User::find($value)?->name),
Want results from more Discord servers?
Add your server