Error Filament\Forms\Components\Select::isOptionDisabled(): Argument #2 ($label) must be of type str

Hi. I have a select field in my form builder that uses user relationship but it throws this error:
Error Filament\Forms\Components\Select::isOptionDisabled(): Argument #2 ($label) must be of type str
Error Filament\Forms\Components\Select::isOptionDisabled(): Argument #2 ($label) must be of type str
My code:
Select::make('model_id')
->relationship('user', 'name')
->required(),
Select::make('model_id')
->relationship('user', 'name')
->required(),
8 Replies
Andrew Wallo
Andrew Wallo2y ago
Maybe try adding a label instead like this:
Forms\Components\Select::make('model_id')
->relationship('user', 'name')
->required()
->label('Model ID'),
Forms\Components\Select::make('model_id')
->relationship('user', 'name')
->required()
->label('Model ID'),
Because Filament will try to use model_id as a string and label for it. In a case such as if you were only using make('model') it would probably work but that depends on your column name...
Atena.D
Atena.DOP2y ago
It didn't work
Andrew Wallo
Andrew Wallo2y ago
What does the Table Column look like for it?
Atena.D
Atena.DOP2y ago
The column name is model_id and the relationship is like this:
public function user()
{
return $this->belongsTo(User::class, 'model_id');
}
public function user()
{
return $this->belongsTo(User::class, 'model_id');
}
Actually, when I change that to ->relationship('user', 'id') is works. but in that case it shows me the id of the users but I want their names Oh, I think I found the reason. I had some records in user table which their name column was NULL and after I deleted them, it's working but in some cases I might have NULL in the name column because that's nullable so what can I do now?
Andrew Wallo
Andrew Wallo2y ago
Hm well it all just depends on a lot of things, there could be a small mistake somewhere... You can take a look at this as an example.. https://github.com/andrewdwallo/erpsaas/blob/master/app/Filament/Pages/CompanyWidgets/Companies.php And you can look at the way my database is set up and the way the models are set up..
GitHub
erpsaas/Companies.php at master · andrewdwallo/erpsaas
Contribute to andrewdwallo/erpsaas development by creating an account on GitHub.
Andrew Wallo
Andrew Wallo2y ago
Thats really all I can do for you... Those are setup as Filament widgets but the same elements should apply...
Atena.D
Atena.DOP2y ago
Thanks 😃
Andrew Wallo
Andrew Wallo2y ago
Also for your database if you want a column to be nullable then use nullable don’t use null, and if it is null don’t put anything
Want results from more Discord servers?
Add your server