src/Http/Middleware/RateLimit.php
public function handle($request, Closure $next)
    {
        if ($request instanceof InternalRequest) {
            return $next($request);
        }

        $route = $this->router->getCurrentRoute();

        if ($route->hasThrottle()) {
            $this->handler->setThrottle($route->getThrottle());
        }

        $this->handler->rateLimitRequest($request, $route->getRateLimit(), $route->getRateLimitExpiration());

        if ($this->handler->exceededRateLimit()) {
            throw new RateLimitExceededException('You have exceeded your rate limit.', null, $this->getHeaders());
        }

        $response = $next($request);

        if ($this->handler->requestWasRateLimited()) {
            return $this->responseWithHeaders($response);
        }

        return $response;
    }
public function handle($request, Closure $next)
    {
        if ($request instanceof InternalRequest) {
            return $next($request);
        }

        $route = $this->router->getCurrentRoute();

        if ($route->hasThrottle()) {
            $this->handler->setThrottle($route->getThrottle());
        }

        $this->handler->rateLimitRequest($request, $route->getRateLimit(), $route->getRateLimitExpiration());

        if ($this->handler->exceededRateLimit()) {
            throw new RateLimitExceededException('You have exceeded your rate limit.', null, $this->getHeaders());
        }

        $response = $next($request);

        if ($this->handler->requestWasRateLimited()) {
            return $this->responseWithHeaders($response);
        }

        return $response;
    }
public function handle ( $ request , Closure $ next ) { if ( $ request instanceof InternalRequest ) { return $ next ( $ request ) ; } $ route = $ this -> router -> getCurrentRoute ( ) ; if ( $ route -> hasThrottle ( ) ) { $ this -> handler -> setThrottle ( $ route -> getThrottle ( ) ) ; } $ this -> handler -> rateLimitRequest ( $ request , $ route -> getRateLimit ( ) , $ route -> getRateLimitExpiration ( ) ) ; if ( $ this -> handler -> exceededRateLimit ( ) ) { throw new RateLimitExceededException ( 'You have exceeded your rate limit.' , null , $ this -> getHeaders ( ) ) ; } $ response = $ next ( $ request ) ; if ( $ this -> handler -> requestWasRateLimited ( ) ) { return $ this -> responseWithHeaders ( $ response ) ; } return $ response ; }
Perform rate limiting before a request is executed.

@param \Dingo\Api\Http\Request $request
@param \Closure                $next

@throws \Symfony\Component\HttpKernel\Exception\HttpException

@return mixed
Perform rate limiting before a request is executed .