dimanche 10 janvier 2021

Opening-hours not working properly Laravel

I want to close my website outside openinghours of the store, but i want to show on the error the opening hours of the next day, but it's showing that we will open in 0 minutes

public function create()
    {
        $currentOpeningTime = OpeningTimes::where('day', today()->dayOfWeekIso)->firstOrFail();
        $openingTime = Carbon::createFromFormat(
            'H:i:s',
            $currentOpeningTime->opening
        );
        $closingTime = Carbon::createFromFormat(
            'H:i:s',
            $currentOpeningTime->closing
        );

        $minutesUntilOpening = now()->minutesUntil($openingTime)->ceilMinute()->count();

        $isStoreOpen = now()->isBetween($openingTime, $closingTime);
        $isStoreClosed = now()->isBetween($closingTime, $openingTime->addDay());

        if ($isStoreClosed && $minutesUntilOpening < 60) {
            abort(401, "We are closed, we will open in " . $minutesUntilOpening . " minutes");
        } else if ($isStoreClosed) {
            abort(401, "We are closed now, we will open at " . $openingTime->hour . ":" . $openingTime->format('i'));
        }

I think maybe it's because it's not getting the day after, because after 00:00 i get the correct text

Aucun commentaire:

Enregistrer un commentaire