我的查询是:
$posts = Post::
whereIn('ID', (
NewsTag::
orderBy('post_date','desc')->with('publisher','newsTopics')
->paginate(12)->pluck('post_id')))
->get();
Newstag.php 模型是这样的:
public function newsTopics() {
return $this->hasOne('App\Models\NewsTopics', 'post_id', 'post_id');
}
public function publisher() {
return $this->hasOne('App\Models\Publisher', 'id', 'publisher_id');
}
当我执行以下操作时,我无法访问 publisher 和 newsTopics:
@foreach($posts as $post)
//doesn't work this way
$post->publisher->name;
//nor like this
$publisher->name;
我怎样才能访问发布者和新闻主题?当我运行这个控制器时,它会查询我想要的内容,但我无权访问它。任何帮助,将不胜感激。谢谢你!
撒科打诨