Please how do I get the start datetime and end datetime of all the months in a given year in Laravel?
CodePudding user response:
You can use this method, If I get your question correctly:
public function getStartAndEndOfMonthForGivenYear(int $year): array
{
$carbon = Carbon::createFromDate($year);
$currentYear = $carbon->floorYear();
$data = array();
for ($i = 0; $i < 12; $i ) {
$data[] = [
'start' => $currentYear->startOfMonth()->toDateTimeString(),
'end' => $currentYear->endOfMonth()->toDateTimeString(),
];
$currentYear->startOfMonth()->addMonth();
}
return $data;
}
CodePudding user response:
$booking = Booking::min('arrival_date')->first();
$reservation = Reservation::max('departure_date')->first();