On this page
ThrottleRequests
class ThrottleRequests (View source)
Traits
Properties
protected RateLimiter | $limiter | The rate limiter instance. |
|
static protected bool | $shouldHashKeys | Indicates if the rate limiter keys should be hashed. |
Methods
int | secondsUntil(DateTimeInterface|DateInterval|int $delay) Get the number of seconds until the given DateTime. |
from InteractsWithTime |
int | availableAt(DateTimeInterface|DateInterval|int $delay = 0) Get the "available at" UNIX timestamp. |
from InteractsWithTime |
DateTimeInterface|int | parseDateInterval(DateTimeInterface|DateInterval|int $delay) If the given value is an interval, convert it to a DateTime instance. |
from InteractsWithTime |
int | currentTime() Get the current system time as a UNIX timestamp. |
from InteractsWithTime |
void | __construct(RateLimiter $limiter) Create a new request throttler. |
|
static string | using(string $name) Specify the named rate limiter to use for the middleware. |
|
static string | with(int $maxAttempts = 60, int $decayMinutes = 1, string $prefix = '') Specify the rate limiter configuration for the middleware. |
|
Response | handle(Request $request, Closure $next, int|string $maxAttempts = 60, float|int $decayMinutes = 1, string $prefix = '') Handle an incoming request. |
|
Response | handleRequestUsingNamedLimiter(Request $request, Closure $next, string $limiterName, Closure $limiter) Handle an incoming request. |
|
Response | handleRequest(Request $request, Closure $next, array $limits) Handle an incoming request. |
|
int | resolveMaxAttempts(Request $request, int|string $maxAttempts) Resolve the number of attempts if the user is authenticated or not. |
|
string | resolveRequestSignature(Request $request) Resolve request signature. |
|
ThrottleRequestsException | buildException(Request $request, string $key, int $maxAttempts, callable|null $responseCallback = null) Create a 'too many attempts' exception. |
|
int | getTimeUntilNextRetry(string $key) Get the number of seconds until the next retry. |
|
Response | addHeaders(Response $response, int $maxAttempts, int $remainingAttempts, int|null $retryAfter = null) Add the limit header information to the given response. |
|
array | getHeaders(int $maxAttempts, int $remainingAttempts, int|null $retryAfter = null, Response|null $response = null) Get the limit headers information. |
|
int | calculateRemainingAttempts(string $key, int $maxAttempts, int|null $retryAfter = null) Calculate the number of remaining attempts. |
|
static void | shouldHashKeys(bool $shouldHashKeys = true) Specify whether rate limiter keys should be hashed. |
Details
protected int secondsUntil(DateTimeInterface|DateInterval|int $delay)
Get the number of seconds until the given DateTime.
protected int availableAt(DateTimeInterface|DateInterval|int $delay = 0)
Get the "available at" UNIX timestamp.
protected DateTimeInterface|int parseDateInterval(DateTimeInterface|DateInterval|int $delay)
If the given value is an interval, convert it to a DateTime instance.
protected int currentTime()
Get the current system time as a UNIX timestamp.
void __construct(RateLimiter $limiter)
Create a new request throttler.
static string using(string $name)
Specify the named rate limiter to use for the middleware.
static string with(int $maxAttempts = 60, int $decayMinutes = 1, string $prefix = '')
Specify the rate limiter configuration for the middleware.
Response handle(Request $request, Closure $next, int|string $maxAttempts = 60, float|int $decayMinutes = 1, string $prefix = '')
Handle an incoming request.
protected Response handleRequestUsingNamedLimiter(Request $request, Closure $next, string $limiterName, Closure $limiter)
Handle an incoming request.
protected Response handleRequest(Request $request, Closure $next, array $limits)
Handle an incoming request.
protected int resolveMaxAttempts(Request $request, int|string $maxAttempts)
Resolve the number of attempts if the user is authenticated or not.
protected string resolveRequestSignature(Request $request)
Resolve request signature.
protected ThrottleRequestsException buildException(Request $request, string $key, int $maxAttempts, callable|null $responseCallback = null)
Create a 'too many attempts' exception.
protected int getTimeUntilNextRetry(string $key)
Get the number of seconds until the next retry.
protected Response addHeaders(Response $response, int $maxAttempts, int $remainingAttempts, int|null $retryAfter = null)
Add the limit header information to the given response.
protected array getHeaders(int $maxAttempts, int $remainingAttempts, int|null $retryAfter = null, Response|null $response = null)
Get the limit headers information.
protected int calculateRemainingAttempts(string $key, int $maxAttempts, int|null $retryAfter = null)
Calculate the number of remaining attempts.
static void shouldHashKeys(bool $shouldHashKeys = true)
Specify whether rate limiter keys should be hashed.
© Taylor Otwell
Licensed under the MIT License.
Laravel is a trademark of Taylor Otwell.
https://laravel.com/api/10.x/Illuminate/Routing/Middleware/ThrottleRequests.html