FleetCart/Modules/Cart/Http/Middleware/CheckCouponUsageLimit.php

30 lines
693 B
PHP
Raw Normal View History

2023-06-11 12:14:03 +00:00
<?php
namespace Modules\Cart\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Modules\Cart\Facades\Cart;
use Modules\Coupon\Exceptions\CouponUsageLimitReachedException;
class CheckCouponUsageLimit
{
/**
* Handle an incoming request.
*
2023-12-03 14:07:47 +00:00
* @param Request $request
* @param Closure $next
*
2023-06-11 12:14:03 +00:00
* @return mixed
2023-12-03 14:07:47 +00:00
* @throws CouponUsageLimitReachedException
2023-06-11 12:14:03 +00:00
*/
2023-12-03 14:07:47 +00:00
public function handle(Request $request, Closure $next): mixed
2023-06-11 12:14:03 +00:00
{
if (Cart::coupon()->usageLimitReached($request->customer_email)) {
throw new CouponUsageLimitReachedException;
}
return $next($request);
}
}