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!5 replies