Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel 拉威尔中间关系数据错误_Laravel_Eloquent - Fatal编程技术网

Laravel 拉威尔中间关系数据错误

Laravel 拉威尔中间关系数据错误,laravel,eloquent,Laravel,Eloquent,这是我的RecentViewController文件代码: $contents = RecentView::where('user_id', $loggedUser) ->with('posts') ->with('profile') ->paginate(12)->toArray(); 我的最新视图型号代码如下: public

这是我的RecentViewController文件代码:

$contents = RecentView::where('user_id', $loggedUser)
                        ->with('posts')
                        ->with('profile')
                        ->paginate(12)->toArray();
我的最新视图型号代码如下:

public function posts()
    {
        return $this->hasOne('App\FeedPost', 'id', 'post_id');
    }

    public function profile()
    {
        return $this->belongsTo('App\Profile', 'user_id', 'id');
    }

运行此代码后收到的数据显示登录用户的详细信息,而不是posts users detaisl。如何更改Retrieving posts用户数据而不是记录的用户数据?

我猜您正在尝试获取该帖子的用户 为了获得帖子用户的详细信息,您需要将配置文件关系移动到
Post
模型中。我希望posts表中有
用户id
。然后用点表示法得到post模型的轮廓关系,如下所示

$contents=RecentView::where('user\u id',$loggedUser)
->带('posts.profile')
->分页(12)->toArray();

感谢您的输入,我们将尝试让您知道它是否有效。谢谢@ravisha。你救了我一天,我很高兴能帮上忙。