useMidnite81\Guardian\Factories\LaravelGuardianFactory;// Using Laravel's built-in cache$guardian =LaravelGuardianFactory::make('weather-conditions', [RateLimitRule::allow(100)->perMinute()], [ErrorHandlingRule::allowFailures(5)->perMinute()]);// Using a custom cache$guardian =LaravelGuardianFactory::create('weather-conditions',newFileStore('/path/to/cache'), [RateLimitRule::allow(100)->perMinute()], [ErrorHandlingRule::allowFailures(5)->perMinute()]);
useMidnite81\Guardian\Guardian;classMyController{publicfunction__construct(protectedGuardian $guardian) {$this->guardian->setIdentifier('spotify-playlist')->setCache($customCache)// Optional: defaults to Laravel's cache->addRules([RateLimitRule::allow(100)->perMinute()])->addErrorRules([ErrorHandlingRule::allowFailures(5)->perMinute()]); }}
Facade (Laravel)
useMidnite81\Guardian\Facades\Guardian;// Using Laravel's built-in cache$guardian =Guardian::make('weather-conditions', [RateLimitRule::allow(100)->perMinute()]);// Using a custom cache$guardian =Guardian::create('weather-conditions',newFileStore('/path/to/cache'), [RateLimitRule::allow(100)->perMinute()], [ErrorHandlingRule::allowFailures(5)->perMinute()]);
$identifier
string
Used to register rate limits and error-handling
$cache
CacheInterface
Cache driver to store rate-limiting and error-handling data
$rules
RateLimitingRulesetInterface|array|null
Ruleset or array of RateLimitRule rules (optional)
$errorRules
ErrorHandlingRulesetInterface|array|null
Ruleset or array of ErrorHandlingRule rules (optional)