Day14
最低限の連載機能を完成させてリリースしました。
Magazine.phpのメソッドで下記のようにして記事を取得しています。(仕様的に単純なhasManyではないため)
public function getPostsQuery()
{
$postIds = PostTag::where('user_id', $this->user_id)
->where('tag_id', $this->tag_id)
->get()
->pluck('post_id');
return Post::with('tags')
->whereIn('id', $postIds);
}
public function getPosts()
{
return $this->getPostsQuery()
->orderBy('created_at')
->get();
}