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
<tr>
<td style="color: white">{{__('discount')}}</td>
<td style="color: white">@if($coupon){{$coupon->discount_value }}
@endif </td>
</tr>
when executing this form
<form action="{{ route('coupons.check') }}" method="POST">
@csrf
<input type="text" name="code" class="form-control text-center" placeholder="
{{ __('cupon code') }}">
<button name="confirm_code" class="btn btn-success col-md">{{ __('Confirm')
}}</button>
</form>