所以我有2个模型,User & Profile,关系设置如下:
/**
* User belongs to many Profile
*
* @return \Illuminate\Database\Eloquent\Relations\belongsToMany
*/
public function profiles()
{
return $this->belongsToMany('App\Models\Profile', 'user_profiles');
}
Run Code Online (Sandbox Code Playgroud)
我有 3 个表、用户、配置文件和 user_profiles(数据透视表)
我的用户表中有一个名为的列,active_profile其中填充了配置文件 ID。
我如何建立关系,以便我可以调用以下内容:
$user->active_profile
以便它将返回active_profile中设置的id的所有配置文件信息?