From 9fd47f396505ddaa9c1bb0104e0c185b08476f58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=A2=E3=83=AA?= Date: Thu, 24 Sep 2020 21:03:22 +0300 Subject: [PATCH] Add perHour and perDay methods to RateLimiting I have found my self using rate-limiting with hours and days quite often, in API subscriptions to be precise. --- src/Illuminate/Cache/RateLimiting/Limit.php | 24 +++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/Illuminate/Cache/RateLimiting/Limit.php b/src/Illuminate/Cache/RateLimiting/Limit.php index 2eee661b25ce..ab3463f51830 100644 --- a/src/Illuminate/Cache/RateLimiting/Limit.php +++ b/src/Illuminate/Cache/RateLimiting/Limit.php @@ -58,6 +58,30 @@ public static function perMinute($maxAttempts) return new static('', $maxAttempts); } + /** + * Create a new rate limit using hours as decay time. + * + * @param int $maxAttempts + * @param int $decayHours + * @return static + */ + public static function perHour($maxAttempts, $decayHours = 1) + { + return new static('', $maxAttempts, 60 * $decayHours); + } + + /** + * Create a new rate limit using days as decay time. + * + * @param int $maxAttempts + * @param int $decayDays + * @return static + */ + public static function perDay($maxAttempts, $decayDays = 1) + { + return new static('', $maxAttempts, 60 * 24 * $decayDays); + } + /** * Create a new unlimited rate limit. *