Closed AHMED-J-ALSAREM closed 9 months ago
No reproduction repository, it needs to be a GitHub repository containing an app.
Check all other issues for reproduction repository examples
This is the solution to the problem
SelectFilter::make('tenant_id') ->label('Domain') ->options(Tenant::whereNotNull('domain')->pluck('domain', 'id')) ->searchable() ->preload(),
This is the solution to the problem
SelectFilter::make('tenant_id') ->label('Domain') ->options(Tenant::whereNotNull('domain')->pluck('domain', 'id')) ->searchable() ->preload(),
What if I use relationships? This option doesn't solve my problem
Try using ->getOptionLabelFromRecordUsing()
method
Forms\Components\Select::make('person_id')
->relationship(
'student',
modifyQueryUsing: fn (Builder $query) => $query->where('is_student', true)
)
->getOptionLabelFromRecordUsing(fn (Model $record) => "{$record->full_name}")
->preload()
->searchable()
->live()
->required(),
I've hit the same issue. The solution from @PrasadChinwal works for me, but it looks to me more like workaround. I could imagine the option label is fetched from the edited $record automatically.
@lukasinko Actually this is well documented. https://filamentphp.com/docs/3.x/forms/fields/select#customizing-the-relationship-option-labels
I believe under the hood the model gets hydrated hence you have access to the attribute. (Not sure though just my understanding)
Package
filament/filament
Package Version
v3.0.0
Laravel Version
v10
Livewire Version
v3.0.0
PHP Version
php.8.1
Problem description
SelectFilter::make('Domain') ->relationship('tenant', 'domain') ->searchable() ->preload(),
Filament\Forms\Components\Select::isOptionDisabled(): Argument #2 ($label) must be of type string, null given, called in C:\htdocs\idara.23.11\vendor\filament\forms\src\Components\Select.php on line 184
Expected behavior
SelectFilter::make('Domain') ->relationship('tenant', 'domain') ->searchable() ->preload(),
Filament\Forms\Components\Select::isOptionDisabled(): Argument #2 ($label) must be of type string, null given, called in C:\htdocs\idara.23.11\vendor\filament\forms\src\Components\Select.php on line 184
Steps to reproduce
SelectFilter::make('Domain') ->relationship('tenant', 'domain') ->searchable() ->preload(),
Filament\Forms\Components\Select::isOptionDisabled(): Argument #2 ($label) must be of type string, null given, called in C:\htdocs\idara.23.11\vendor\filament\forms\src\Components\Select.php on line 184
Reproduction repository
SelectFilter::make('Domain') ->relationship('tenant', 'domain') ->searchable() ->preload(),
Relevant log output