filamentphp / filament

A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS.
https://filamentphp.com
MIT License
17.65k stars 2.76k forks source link

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 #10086

Closed AHMED-J-ALSAREM closed 9 months ago

AHMED-J-ALSAREM commented 9 months ago

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

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
danharrin commented 9 months ago

No reproduction repository, it needs to be a GitHub repository containing an app.

danharrin commented 9 months ago

Check all other issues for reproduction repository examples

AHMED-J-ALSAREM commented 9 months ago

This is the solution to the problem

SelectFilter::make('tenant_id') ->label('Domain') ->options(Tenant::whereNotNull('domain')->pluck('domain', 'id')) ->searchable() ->preload(),

CatShredengera commented 1 month ago

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

PrasadChinwal commented 1 month ago

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(),
lukasinko commented 2 weeks ago

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.

PrasadChinwal commented 2 weeks ago

@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)