//查出所有包含了[laravel]这个标签的所有文章 // Post model class Post extends Eloquent {原文链接:https://www.f2er.com/note/422762.htmlpublic function tags() { return $this->belongsToMany(‘Tag’); }
}
// Tag model
class Tag extends Eloquent()
{public function posts() { return $this->belongsToMany(‘Post’); }
}
// 查询自上周发布以来包含了 laravel 标签的所有文章
$posts = Post::whereHas(‘tags’, function($query)
{
$query->where(‘name’, ‘=’, ‘laravel’);
})->where(‘published_at’, ‘ >= ‘, Carbon\Carbon::now()->subWeek())->get();