Laravel Throttle

Laravel Throttle is a rate limiter for Laravel. The Throttle middleware does help you to  restrict an action like a user request based on a number of attempts inside a time window.  This works for throttling requests for logins but if you want a custom action you need to create it by yourself or download a package. There is a throttle inside Laravel called RateLimiter. It's inside Illuminate/Cache/RateLimiter. RateLimiter uses a cache store to keep two parameters. It holds the window of time to register new attempts and the number of attempts. Using app helper you can call it anywhere in your code. 

Installation

You need PHP 7.2-8.0. To get the latest version requires using a composer. 

$ composer require graham-campbell/throttle:^8.1

You are not using automatic package discovery, you need to register that in the service provider in your config/app.php.

GrahamCampbell\Throttle\ThrottleServiceProvider

You can also alias our facade.

  'Throttle' => GrahamCampbell\Throttle\Facades\Throttle::class,

Configuration

Publish all vendor assets.

$ php artisan vendor:publish
This step will create a config/throttle.php file in your app. There is one config option called Cache driver that defines the cache driver to be used. Usage The Throttle class is bound to the IoC container as ‘throttle’ and it can be accessed as Facades\Throttle facade. There are 6 public methods of interest. They are get, attempt, hit, clear, count, check. Facade will dynamically pass static method calls to the throttle object in the ioc container . Throttler/ThrottlerInterface defines public methods a throttler class must implement. All 5 methods except get accept n parameters. Factories\FactoryInterface-It defines public methods a throttler factory class must implement such as a class must only implement one method. ThrottleServiceprovider class has no public methods of interest. It should be added to the array in config/app.php and it will set up ioc bindings.