Carbrand::all()->pluck('carbrand_name', 'id') is causing incorrect integer value: '"2"' error

I have this in my select box in Form:
Select::make('carbrand')
->label('Car Brand')
->required()
->options(Carbrand::all()->pluck('carbrand_name', 'id'))
Select::make('carbrand')
->label('Car Brand')
->required()
->options(Carbrand::all()->pluck('carbrand_name', 'id'))
in the Form for create resource is causing this error on Save:
SQLSTATE[HY000]: General error: 1366 Incorrect integer value: '"5"' for column 'carbrand' at row 1
SQLSTATE[HY000]: General error: 1366 Incorrect integer value: '"5"' for column 'carbrand' at row 1
I guess it is trying to save a string instead of integer - which the column in migration is saved to. How to force Filament to convert the id to integer when saving? Is there any other way to do it without pluck?
Solution:
Cast it as an integer in your model.
Jump to solution
1 Reply
Solution
awcodes
awcodes2mo ago
Cast it as an integer in your model.