Laravel 拉威尔中间关系数据错误
这是我的RecentViewController文件代码:Laravel 拉威尔中间关系数据错误,laravel,eloquent,Laravel,Eloquent,这是我的RecentViewController文件代码: $contents = RecentView::where('user_id', $loggedUser) ->with('posts') ->with('profile') ->paginate(12)->toArray(); 我的最新视图型号代码如下: public
$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。你救了我一天,我很高兴能帮上忙。