0

I am trying to restrict usage of a certain endpoint to 10 times per day per user, and I can see how to do it for a certain number of times per minute. Please note that this is within a controller, not as middleware.

    $executed = RateLimiter::attempt(
        'user-send-test-' . Auth::user()->id,
        $perDay = 10,
        function () {
            // some process
        }
    );
mankowitz
  • 1,864
  • 1
  • 14
  • 32
  • the second parameter of `attempt()` is in minutes, as 10 per minutes. it doesn't matter the name you give to the variable `$perDay` or `$perCentury` it will still be per minute. – N69S May 29 '22 at 22:31
  • right. I know that. I was just showing what I wanted. – mankowitz May 30 '22 at 01:05

1 Answers1

0

To use the rate limiter per day, use the fourth parameter of the method attemp() which is the decay (how long an attempt need to be counted for) but I never tested it.

$executed = RateLimiter::attempt(
    'user-send-test-' . Auth::user()->id,
    $perDay = 10,
    function () {
        // some process
    },
    60*60*24 // or 86400
    );

If you still encounter issues with this example, I suggest you copy the RateLimiter class as it is very small and adapt its code.

N69S
  • 16,110
  • 3
  • 22
  • 36