Laravel - Rate Limiting - Basic Usage

The Illuminate\Support\Facades\RateLimiter facade may be used to interact with the rate limiter. The simplest method offered by the rate limiter is the attempt method, which rate limits a given callback for a given number of seconds.

The attempt method returns false when the callback has no remaining attempts available; otherwise, the attempt method will return the callback's result or true. The first argument accepted by the attempt method is a rate limiter "key", which may be any string of your choosing that represents the action being rate limited:

    use Illuminate\Support\Facades\RateLimiter;
    $executed = RateLimiter::attempt(
        $perMinute = 5,
        function() {
            // Send message...
    if (! $executed) {
      return 'Too many messages sent!';