代码如下:
private function generateDates()
{
$startDate = Carbon::now()->subYears(2);
$endDate = Carbon::now();
$period = CarbonPeriod::create($startDate, $endDate, CarbonPeriod::EXCLUDE_END_DATE);
foreach ($period->toArray() as $date) {
echo $date->format('Y-m-d') . "\n";
}
}