F
Filament12mo ago
Gotfers

Form: unknown column when using relationship

Hi, I have a problem when I am trying to create or update a user for whom I have added a "Institution" relationship. What is weird is I don't get the same error with the skill relationship. I have the following error : SQLSTATE[42S22]: Column not found: 1054 Unknown column 'institution' in 'field list' update users SET institution = [ "1" ], users.updated_at = 2023 -12 -23 15: 20: 14 WHERE id = 1 Here is my User Model (I stripped what's not useful) class User extends Authenticatable { protected $fillable = [ 'name', 'firstname', 'email', 'email_verified_at', 'password', 'bio', ]; public function institutions(): BelongsToMany { return $this->belongsToMany(Institution::class); } public function skills(): BelongsToMany { return $this->belongsToMany(Skill::class); } } And my UserResource : class UserResource extends Resource { public static function form(Form $form): Form { return $form ->schema([ TextInput::make('name') ->required(), TextInput::make('firstname') ->required(), TextInput::make('email') ->email() ->required(), RichEditor::make('bio') ->disableToolbarButtons([ 'attachFiles', ]), Select::make('skill') ->multiple() ->relationship(name: 'skills', titleAttribute: 'title') ->preload() ->searchable(), Select::make('institution') ->relationship(name: 'institutions', titleAttribute: 'name') ->searchable() ->preload(), ]); } Thanks for your help!
Solution:
Is it because I declared the relationship as belongsToMany? In that case, is it mandatory to use a multiple select to store data?
Jump to solution
2 Replies
Gotfers
GotfersOP12mo ago
Weird fact If I add "->multiple()" to "Select::make('institution')", there is no more problem...
Solution
Gotfers
Gotfers12mo ago
Is it because I declared the relationship as belongsToMany? In that case, is it mandatory to use a multiple select to store data?
Want results from more Discord servers?
Add your server