Strange new error in select component

Hi I have had the same resource for a few weeks and it has been working without issues, but this morning I got a strange error. I have created separate form for the 'CreatePage like this:
public function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('name')
->required()
->maxLength(255),
Forms\Components\Select::make('exchange_info_id')
->searchable()
->relationship('exchangeInfo'),
]);
}
public function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('name')
->required()
->maxLength(255),
Forms\Components\Select::make('exchange_info_id')
->searchable()
->relationship('exchangeInfo'),
]);
}
there is 1322 records in the exchangeInfo, which is why I cannot use a 'simple' select The form renders correctly, when I try to search for an entry I get this error:
foreach() argument must be of type array|object, null given
foreach() argument must be of type array|object, null given
Solution:
It must have been something with the relation. I have changed the select to this and now it works: ```...
Jump to solution
2 Replies
rabol
rabolOP2w ago
I have a feature that capture all unhandled exceptions and the stack trace points to the select component
#0 /Users/rabol/code/web/zynkto/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(290): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(2, 'foreach() argum...', '/Users/rabol/co...', 1084)
#1 /Users/rabol/code/web/zynkto/vendor/filament/forms/src/Components/Select.php(1084): Illuminate\Foundation\Bootstrap\HandleExceptions->Illuminate\Foundation\Bootstrap\{closure}(2, 'foreach() argum...', '/Users/rabol/co...', 1084)
#2 /Users/rabol/code/web/zynkto/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(311): Filament\Forms\Components\Select->Filament\Forms\Components\{closure}(Object(Illuminate\Database\Eloquent\Builder))
#3 /Users/rabol/code/web/zynkto/vendor/filament/forms/src/Components/Select.php(1081): Illuminate\Database\Eloquent\Builder->where(Object(Closure))
#4 /Users/rabol/code/web/zynkto/vendor/filament/forms/src/Components/Select.php(718): Filament\Forms\Components\Select->applySearchConstraint(Object(Illuminate\Database\Eloquent\Builder), 'BTC')
#5 /Users/rabol/code/web/zynkto/vendor/filament/support/src/Concerns/EvaluatesClosures.php(35): Filament\Forms\Components\Select::Filament\Forms\Components\{closure}(Object(Filament\Forms\Components\Select), 'BTC')
#6 /Users/rabol/code/web/zynkto/vendor/filament/forms/src/Components/Select.php(629): Filament\Support\Components\Component->evaluate(Object(Closure), Array)
#7 /Users/rabol/code/web/zynkto/vendor/filament/forms/src/Components/Select.php(647): Filament\Forms\Components\Select->getSearchResults('BTC')
#8 /Users/rabol/code/web/zynkto/vendor/filament/forms/src/Concerns/SupportsSelectFields.php(85): Filament\Forms\Components\Select->getSearchResultsForJs('BTC')
#9 /Users/rabol/code/web/zynkto/vendor/filament/forms/src/Concerns/InteractsWithForms.php(164): Filament\Forms\ComponentContainer->getSelectSearchResults('data.exchange_i..
#0 /Users/rabol/code/web/zynkto/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(290): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(2, 'foreach() argum...', '/Users/rabol/co...', 1084)
#1 /Users/rabol/code/web/zynkto/vendor/filament/forms/src/Components/Select.php(1084): Illuminate\Foundation\Bootstrap\HandleExceptions->Illuminate\Foundation\Bootstrap\{closure}(2, 'foreach() argum...', '/Users/rabol/co...', 1084)
#2 /Users/rabol/code/web/zynkto/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(311): Filament\Forms\Components\Select->Filament\Forms\Components\{closure}(Object(Illuminate\Database\Eloquent\Builder))
#3 /Users/rabol/code/web/zynkto/vendor/filament/forms/src/Components/Select.php(1081): Illuminate\Database\Eloquent\Builder->where(Object(Closure))
#4 /Users/rabol/code/web/zynkto/vendor/filament/forms/src/Components/Select.php(718): Filament\Forms\Components\Select->applySearchConstraint(Object(Illuminate\Database\Eloquent\Builder), 'BTC')
#5 /Users/rabol/code/web/zynkto/vendor/filament/support/src/Concerns/EvaluatesClosures.php(35): Filament\Forms\Components\Select::Filament\Forms\Components\{closure}(Object(Filament\Forms\Components\Select), 'BTC')
#6 /Users/rabol/code/web/zynkto/vendor/filament/forms/src/Components/Select.php(629): Filament\Support\Components\Component->evaluate(Object(Closure), Array)
#7 /Users/rabol/code/web/zynkto/vendor/filament/forms/src/Components/Select.php(647): Filament\Forms\Components\Select->getSearchResults('BTC')
#8 /Users/rabol/code/web/zynkto/vendor/filament/forms/src/Concerns/SupportsSelectFields.php(85): Filament\Forms\Components\Select->getSearchResultsForJs('BTC')
#9 /Users/rabol/code/web/zynkto/vendor/filament/forms/src/Concerns/InteractsWithForms.php(164): Filament\Forms\ComponentContainer->getSelectSearchResults('data.exchange_i..
I have tried to clear all cache, republish Livewire assets etc. But... I get this: URL: https://zynkto.test/livewire/update Input: {"_token":"gxMlQ0qJhfoNNnjR5lTZi80qNTYBCSt0rjpnPtDj","components":[{"snapshot":"{"data":{"record":null,"data":[{"name":null,"exchange_info_id":null},{"s":"arr"}],"previousUrl":"https:\/\/zynkto.test\/dashboard\/user-strategies","mountedActions":[[],{"s":"arr"}],"mountedActionsArguments":[[],{"s":"arr"}],"mountedActionsData":[[],{"s":"arr"}],"defaultAction":null,"defaultActionArguments":null,"componentFileAttachments":[[],{"s":"arr"}],"mountedFormComponentActions":[[],{"s":"arr"}],"mountedFormComponentActionsArguments":[[],{"s":"arr"}],"mountedFormComponentActionsData":[[],{"s":"arr"}],"mountedFormComponentActionsComponents":[[],{"s":"arr"}],"mountedInfolistActions":[[],{"s":"arr"}],"mountedInfolistActionsData":[[],{"s":"arr"}],"mountedInfolistActionsComponent":null,"mountedInfolistActionsInfolist":null,"savedDataHash":null},"memo":{"id":"3ASzJIxp9HA5NuNFC1Pm","name":"app.filament.app.resources.user-strategy-resource.pages.create-user-strategy","path":"dashboard\/user-strategies\/create","method":"GET","children":[],"scripts":[],"assets":[],"errors":[],"locale":"en"},"checksum":"bc803e897ed9360c369b36b14f8bf5fdc79efbeda2c12ac42bb832711db79e1d"}","updates":[],"calls":[{"path":"","method":"getFormSelectSearchResults","params":["data.exchange_info_id","BTC"]}]}]}
Solution
rabol
rabol2w ago
It must have been something with the relation. I have changed the select to this and now it works:
Forms\Components\Select::make("exchange_info_id")
->searchable()
->getSearchResultsUsing(
fn(string $search): array => ExchangeInfo::where(
"symbol",
"like",
"%{$search}%"
)
->limit(50)
->pluck("symbol", "id")
->toArray()
)
->getOptionLabelUsing(
fn($value): ?string => ExchangeInfo::find($value)?->symbol
),
Forms\Components\Select::make("exchange_info_id")
->searchable()
->getSearchResultsUsing(
fn(string $search): array => ExchangeInfo::where(
"symbol",
"like",
"%{$search}%"
)
->limit(50)
->pluck("symbol", "id")
->toArray()
)
->getOptionLabelUsing(
fn($value): ?string => ExchangeInfo::find($value)?->symbol
),

Did you find this page helpful?