相关疑难解决方法(0)

Laravel hasOne 通过数据透视表

所以我有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的所有配置文件信息?

php relationship laravel eloquent

7
推荐指数
2
解决办法
8713
查看次数

标签 统计

eloquent ×1

laravel ×1

php ×1

relationship ×1