因此,我已2种型号,用户&资料,该关系被设置为如下:Laravel hasOne
/**
* User belongs to many Profile
*
* @return \Illuminate\Database\Eloquent\Relations\belongsToMany
*/
public function profiles()
{
return $this->belongsToMany('App\Models\Profile', 'user_profiles');
}
我有3个表,用户简档& user_profiles(透视表)
我在我的用户表中有一个名为active_profile
的列,它填充了一个配置文件ID。
我如何建立关系,以便我可以调用类似如下:
$user->active_profile
,这样它会返回所有的资料信息在active_profile设定的ID?
以下其中一条帖子是否回答你的问题? –