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

willy12's avatar

Coupon expiry date

am having issues with my application when i have created a coupon in the backend and give an expiry date it dosen't expire when i change the date in my database but if i change to a previous month it shows invalid but when change just few days after expiry it still shows valid of which it should expire on date given. controller code public function store(Request $request) { $request->validate([ 'name' => 'required', 'discount' => 'required', 'validity' => 'required', ]);

    Coupon::insert([
        'name' => strtoupper($request->name),
        'discount' => $request->discount,
        'validity' => $request->validity,
        'created_at'=> Carbon::now(),
    ]);
    return redirect()->back();
}

my index code

@foreach($coupons as $coupon) {{$coupon->id}} {{$coupon->name}} {{$coupon->discount}} {{Carbon\Carbon::parse($coupon->validity)->format('D, d F Y')}} @if($coupon->validity>= Carbon\Carbon::now()->format('Y-m-d')) Valid @else Invalid @endif Edit Delete @endforeach
0 likes
2 replies

Please or to participate in this conversation.