How can I iterate over a date range with foreach in a FilamentPHP Laravel app?

I'm using FilamentPHP in my Laravel application. I have two date picker components for selecting a start date (date_begin) and an end date (date_end). Given user-selected dates, such as '2023-08-14' for date_begin and '2023-09-14fordate_end, how can I use a foreach` loop to generate or process information for each day in this date range?"
4 Replies
awcodes
awcodes16mo ago
$start = Carbon::parse('2022-01-01');
$end = Carbon::parse('2022-01-15');
$dates = Carbon::range($start, $end, '1 day');

foreach ($dates as $date) {
echo $date->format('Y-m-d') . PHP_EOL;
}
$start = Carbon::parse('2022-01-01');
$end = Carbon::parse('2022-01-15');
$dates = Carbon::range($start, $end, '1 day');

foreach ($dates as $date) {
echo $date->format('Y-m-d') . PHP_EOL;
}
islom_ilkhomov
islom_ilkhomovOP16mo ago
Doeas carbon work in V2 verison?
awcodes
awcodes16mo ago
yes, Carbon is not a Filament thing. and Laravel includes it
awcodes
awcodes16mo ago
Want results from more Discord servers?
Add your server