acidf0x / laravel-ez-throttle
A simple Laravel Throttle extension
v1.0.0
2018-01-11 03:04 UTC
Requires
- php: >=7.0
- laravel/framework: ~5.5
Requires (Dev)
- orchestra/testbench: ~3.0
This package is not auto-updated.
Last update: 2025-04-15 14:38:30 UTC
README
A simple Laravel Throttle extension
Installation
install using composer:
composer require acidf0x/laravel-ez-throttle
Basic Usage
Start by creating an Throttle
instance
use AcidF0x\EzThrottle\Throttle; $throttle = new Throttle(); // or $throttle = new Throttle($throttleKey , $maxAttempts, $decayMinutes); // increase hit count $throttle->hit() if ($throttle->isBlock()) { echo $throttle->getErrorMsg(); // "Too Many Requests. Please try again in 1 minutes" } else { // ... if ( ... ) { $throttle->clear(); } }
or use the EzThrottle
trait if you want
use AcidF0x\EzThrottle\Foundation\EzThrottle; class SomeController extends Controller { use EzThrottle; $protected $ThrottleKey = 'LoginThrottle'; $protected $maxAttempts = '3'; $protected $decayMinutes = '1'; public function doLogin() { //..... // increase hit count $this->hit() if ($this->isBlock()) { return $this->getErrorMsg(); // "Too Many Requests. Please try again in 1 minutes" } else { // ... if ( ... ) { $this->clear(); } } //...... } }
Customize
php artisan vendor:publish --provider=AcixF0x\Ezthrrotle\EzthrottleServiceProvider
Localization
# resources/lang/vendor/ezthrottle/en/error.php return [ 'sec'=> 'Too Many Requests. Please try again in :sec seconds', 'min'=> 'Too Many Requests. Please try again in :min minutes', 'hour'=> 'Too Many Requests. Please try again in :hour hours', 'days'=> 'Too Many Requests. Please try again in :day days', ];
Config
# config/ezthrottle.php return [ 'defaultThrottleKey' => 'throttle', 'defaultDecayMinutes' => '1', 'defaultMaxAttempts' => '3' ];
Todos
- change Trait Method
- Test and support Variable Laravel Ver. (5.*)
- Change Composer Dependency