Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

COUPDEGRACES's avatar

How use if else statement date in blade if date isPast .

I have button in blade.php

      <button type="submit" class="btn btn-{{ is_null($in) ? 'primary' : 'secondary' }} mr-1" {{ is_null($in) ? '' : 'disabled' }}>Time In</button>
                    
                    <button type="submit" class="btn btn-{{ is_null($in) ? 'secondary' : (is_null($out) ? 'primary' : 'secondary') }}" {{ is_null($in) ? 'disabled' : (is_null($out) ? '' : 'disabled') }}>Time Out</button>
                

and here i have table called "absensi", is colum and tipe date i have

status ENUM enum('IN', 'OUT', 'LATE') 

how to use if else statement when date is 16:00 he can click button Time in , but what is entered into the database is late, not in or out

0 likes
2 replies
COUPDEGRACES's avatar

im already try this sir ,

            $now = Carbon::now();
            $start = Carbon::createFromTimeString('14:00');
            $end = Carbon::createFromTimeString('22:00')->addDay();
            if($now->between($start, $end)){
                $attendance = new Attendance();
                $attendance->id_user = auth()->user()->id;
                $attendance->waktu   = Carbon::now()->format('Y-m-d H:i:s');
                $attendance->lokasi  = $request->address;
                $attendance->gambar  = $request->image;
                $attendance->status  = 'TELAT';
                $attendance->save();
                        }
            else
            {
                $attendance = new Attendance();
                $attendance->id_user = auth()->user()->id;
                $attendance->waktu   = Carbon::now()->format('Y-m-d H:i:s');
                $attendance->lokasi  = $request->address;
                $attendance->gambar  = $request->image;
                $attendance->status  = 'IN';
                $attendance->save();
            }

but when im click button Time In , and i check Database, thats status still like this sir https://prnt.sc/10tpcpi whats i want is https://prnt.sc/10tpd5x Status : Telat .

whats wrong my code sir

Please or to participate in this conversation.