3
我有文章,並在每個文件的相應的功能標籤型號:Laravel交叉路口數據
Article.php:
public function tags()
{
return $this->belongsToMany('App\Tag')->withTimestamps();
}
Tag.php:
public function articles()
{
return $this->belongsToMany('App\Article');
}
在刀片觀點,我可以通過致電
@foreach($tag->articles as $article)
...
@endforeach
從上面,我可以訪問一個標籤的文章數量。我們如何過濾具有多個標籤的商品,僅說明在標籤模型中同時具有tag1
和tag2
的商品?