在我的用户模型中,我有以下代码
public function profile()
{
return $this->hasOne(UserProfile::class);
}
在轮廓模型中,
public function user()
{
return $this->belongsTo(User::class);
}
create 方法正在工作,但是当我尝试使用以下代码更新配置文件时,它正在创建一个新的配置文件,并且不会更新配置文件信息。
$profile = new UserProfile();
$profile->dob = '1999-03-20';
$profile->bio = 'A professional programmer.';
$profile->facebook = 'http://facebook.com/test/1';
$profile->github = 'http://github.com/test/1';
$profile->twitter = 'http://twitter.com/test/1';
$user = User::find($userId);
$res = $user->profile()->save($profile);
在一对一关系中更新的正确方法是什么?
一只萌萌小番薯
慕工程0101907
慕斯709654