class BlogPost extends Model
{
...
public function tags()
{
return $this->belongsToMany('App\BlogTag', 'blog_post_tags');
}
...
}
foreach($post->tags as $tag)
{
echo $tag->name;
}
HasMany('App\Post', 'category_id', 'id')
BelongsTo('App\Category', 'category_id', 'id')
Category::with('posts')
$category->posts()
Posts::where('category_id', $catid)