I have Article and Tag models with corresponding functions in each files:
Article.php:
public function tags()
{
return $this->belongsToMany('App\Tag')->withTimestamps();
}
Tag.php:
public function articles()
{
return $this->belongsToMany('App\Article');
}
On Blade view, I can access articles with a corresponding tag by calling
@foreach($tag->articles as $article)
...
@endforeach
From above, I can access a number of articles for a single tag. How can we filter articles with multiple tags, say only articles which have both tag1
and tag2
in a Tag model?
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2gzRWDD
via IFTTT
Aucun commentaire:
Enregistrer un commentaire