I need to make a query in eloquent that brings me the records dated for the day after the current day. In other words, I need today, Friday 7/1, to load the records whose date entered in the variable $fechaip is equal to the following day. But, not taking into account Saturdays and Sundays. Is it possible to do something like this? To get the current date I suppose I can use Carbon... for example something like:
$today = Carbon\Carbon::now()
and then maybe use
$date = $today->addDay();
I think this would work, but how would I except Saturdays and Sundays?
CodePudding user response:
// Starts on next day
$date= Carbon::tomorrow();
// Format N = 1 - for mondays, 7 - for sundays, here you can add conditions to ignore some days.
// If 6 or 7 (saturday or sunday), pass to the next day.
while (in_array($date->format('N'), [6, 7])) {
// Next day
$date->addDays(1);
}
CodePudding user response:
$today = Carbon\CarbonImmutable::now(); // use immutable so $today is not modified
$date = $today->addWeekday();