I want to get all the Thursdays of a year using Carbon and save it on DB.
so far I could only store the Thursdays of current month. please advice me how to make it for the whole year once.
current code
public function getThursdays()
{
return new \DatePeriod(
Carbon::parse("first thursday of this month"),
CarbonInterval::week(),
Carbon::parse("first thursday of next month")
);
}
public function handle()
{
$thursdays = $this->getThursdays();
foreach ($thursdays as $thursday)
{
$Weeks = new Week();
$Weeks->week_starting_date = $thursday;
$Weeks->save();
}
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire