why this function don’t pass the coupon data to view in PHP Laravel?

I have created an online store, but there is a problem that when I enter the discount code in, the condition is executed correctly and returns a message of success of the operation, but no data for the entered discount code is returned.

the check function

public function coupon_check()
        $coupon = Coupon::where('code', request()->post('code'))->first();

        if (isset($coupon) || !empty($coupon)) {
            toast('Successfully !!!', 'success');
            return redirect()->back()->with(['coupon'=>$coupon]);
        } else {
            toast('Not Found !!!', 'error');
            return redirect()->back();

in here
               <td style="color: white">{{__('discount')}}</td>
               <td style="color: white">@if($coupon){{$coupon->discount_value }} 
                 @endif </td> 

when executing this form
       <form action="{{ route('coupons.check') }}" method="POST">
           <input type="text" name="code" class="form-control text-center" placeholder=" 
               {{ __('cupon code') }}">
            <button name="confirm_code" class="btn btn-success col-md">{{ __('Confirm') 


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

When you use with, you create a session, and to access that session, you should use session helper. So change your if statement like this:

@if(session('coupon')){{session('coupon')->discount_value }}

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x