FilamentF
Filament14mo ago
Tuim

Select with live() and searchable()

Hi all,

I am trying to make a double select (depending on relation) that is searchable.

First of all I made a new component with artisan make:form-field to create a re-usable component. This component has the following schema, pretty much following the documentation

$this->schema([
    Select::make('category')
        ->options(Category::query()->whereNull('parent_id')->get()->pluck('label', 'id'))
        ->live(),

    Select::make('sub_category')
        ->searchable()
        ->options(function (Get $get) {
            $valueToSearchFor = $get('category');
            if (blank($valueToSearchFor)) {
                return [];
            }

            return Category::query()
                ->where('parent_id', $get('_stabu_selector'))
                ->get()->pluck('label', 'id');
        })
]);


However if I add ->searchable() to the first select it appears to stop working. The 2nd dropdown isn't populated according to the query (just stays empty) There is no error message really.
Was this page helpful?