//查出所有包含了[laravel]这个标签的所有文章 // Post model class Post extends Eloquent {public 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();