function getDatesInRange($dates, $start, $end) {
$datesInRange = $dates->filter(function ($date) use ($start, $end) {
if ((int) $start->format('Y') === (int) $end->format('Y')) {
$start->year((int)$date->format('Y'));
$end-> year((int)$date->format('Y'));
} elseif ((int) $start->format('Y') < (int) $end->format('Y')) {
if ((int) $date->format('m') >= (int) $start->format('m')) {
$start->year((int) $date->format('Y'));
$end->year((int) $date->format('Y'))->addYears(1);
} else {
$end->year((int) $date->format('Y'));
$start->year((int) $date->format('Y'))->subYears(1);
}
}
return Carbon::parse($date)->isBetween($start, $end);
});
return $datesInRange;
}