我想显示过去六个月的所有文章?
$articles = Articles::whereRaw('MONTH(created_at) ='.$month)->where('approved',1)->paginate(10);
答案 0 :(得分:8)
使用Carbon:
$articles=Article::where("created_at",">", Carbon::now()->subMonths(6))->get();
您需要导入名称空间以使用Carbon:
use Carbon\Carbon;