Getting a Guardian instance
Guardian instances can be obtained in several ways, with the recommended method being via Guardian factories.
Methods to Get a Guardian Instance
Required and Optional Arguments
The Guardian class requires the following arguments:
Argument
Type
Description
$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)
$cachePrefix
string
Prefix for cache keys (default: 'guardian')
Note: In Laravel's
make
method,$cache
is not required as it defaults to Laravel's cache.
Factory Instances
Non-Laravel Projects
Laravel Projects
Direct Class Instantiation
Dependency Injection (Laravel)
Facade (Laravel)
Last updated