Download the PHP package cellard/throttle without Composer
On this page you can find all versions of the php package cellard/throttle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download cellard/throttle
More information about cellard/throttle
Files in cellard/throttle
Package throttle
Short Description Laravel Throttle Service may throttle any events, not only requests
License MIT
Informations about the package throttle
Laravel Throttle Service
Laravel built-in throttling allows to rate limit access to routes. But what about other processes, e.g. sending sms?
For example, you may need to limit amount of sms, user allowed to receive from your service. Or maybe you need to limit number of comments, user allowed to write in some time period.
This service can throttle any event you need:
Installation
composer require Cellard/throttle
Register Service Provider in config/app.php
file.
Publish the package config file and migrations to your application. Run these commands inside your terminal.
php artisan vendor:publish --provider="Cellard\Throttle\ThrottleServiceProvider"
And also run migrations.
php artisan migrate
Setup
Set up your throttle service.
Exactly the same, but with helpers.
Then register your service in config/throttle.php
.
Error messages
By default error messages looks like Next :event after :interval
Next sms after 23 hours 32 minutes 13 seconds
You may define custom error messages.
Placeholders:
- limit — number of events (defined in rule)
- seconds — number of seconds (defined in rule)
- event — name of service (defined in config file)
- interval -
CarbonInterval
object (time left to the next allowed hit)
Usage
Or in try-catch style
Also you may use helper function.
What is subject
?
Subject
is a scope.
You may check availability without subject.
It means that service will check limitations without reference to the exact phone number.
Subject means that service will check limitations per phone.
Pick up your room before you go out
Throttle Service stores records in its table, and you may want to clear it.
php artisan throttle:clean
Will remove obsolete records.
You may schedule it to run once a day or week...