多对多关联拿不到中间表pivot数据

浏览:279 发布日期:2021/03/15 分类:ThinkPHP6专区
manager 表:    /**
     * 多对多关联管理角色
     * @return BelongsToMany
     */
    public function roles()
    {
        return $this->belongsToMany(
            Role::class,
            'manager_role',
            'role_id',
            'manager_id'
        );
    }
然后通过        foreach ($manager->roles as $item){
            dd($item->pivot->toArray());
        }
拿到的数据为空

最佳答案
评论( 相关
后面还有条评论,点击查看>>