Gate
class Gate implements Gate
Traits
Properties
protected Container | $container | The container instance. |
|
protected callable | $userResolver | The user resolver callable. |
|
protected array | $abilities | All of the defined abilities. |
|
protected array | $policies | All of the defined policies. |
|
protected array | $beforeCallbacks | All of the registered before callbacks. |
|
protected array | $afterCallbacks | All of the registered after callbacks. |
Methods
Throws an unauthorized exception.
Create a new gate instance.
Determine if a given ability has been defined.
Define a new ability.
Define abilities for a resource.
Create the ability callback for a callback string.
Define a policy class for a given class type.
Register a callback to run before all Gate checks.
Register a callback to run after all Gate checks.
Determine if the given ability should be granted for the current user.
Determine if the given ability should be denied for the current user.
Determine if the given ability should be granted for the current user.
Determine if the given ability should be granted for the current user.
Get the raw result from the authorization callback.
Resolve and call the appropriate authorization callback.
Call all of the before callbacks and return if a result is given.
Call all of the after callbacks with check result.
Resolve the callable for the given ability and arguments.
Get a policy instance for a given class.
Build a policy class instance of the given type.
Resolve the callback for a policy check.
Call the "before" method on the given policy, if applicable.
Format the policy ability into a method name.
Resolve the user from the user resolver.
Get all of the defined abilities.
Details
in
HandlesAuthorization at line 13
protected Response
allow(string|null $message = null)
Create a new access response.
in
HandlesAuthorization at line 26
protected void
deny(string $message = 'This action is unauthorized.')
Throws an unauthorized exception.
at line 67
void
__construct(Container $container, callable $userResolver, array $abilities = [], array $policies = [], array $beforeCallbacks = [], array $afterCallbacks = [])
Create a new gate instance.
at line 84
bool
has(string $ability)
Determine if a given ability has been defined.
at line 98
$this
define(string $ability, callable|string $callback)
Define a new ability.
at line 119
$this
resource(string $name, string $class, array $abilities = null)
Define abilities for a resource.
at line 141
protected Closure
buildAbilityCallback(string $callback)
Create the ability callback for a callback string.
at line 157
$this
policy(string $class, string $policy)
Define a policy class for a given class type.
at line 170
$this
before(callable $callback)
Register a callback to run before all Gate checks.
at line 183
$this
after(callable $callback)
Register a callback to run after all Gate checks.
at line 197
bool
allows(string $ability, array|mixed $arguments = [])
Determine if the given ability should be granted for the current user.
at line 209
bool
denies(string $ability, array|mixed $arguments = [])
Determine if the given ability should be denied for the current user.
at line 221
bool
check(string $ability, array|mixed $arguments = [])
Determine if the given ability should be granted for the current user.
at line 239
Response
authorize(string $ability, array|mixed $arguments = [])
Determine if the given ability should be granted for the current user.
at line 257
protected mixed
raw(string $ability, array|mixed $arguments = [])
Get the raw result from the authorization callback.
at line 294
protected bool
callAuthCallback(Authenticatable $user, string $ability, array $arguments)
Resolve and call the appropriate authorization callback.
at line 309
protected bool|null
callBeforeCallbacks(Authenticatable $user, string $ability, array $arguments)
Call all of the before callbacks and return if a result is given.
at line 329
protected void
callAfterCallbacks(Authenticatable $user, string $ability, array $arguments, bool $result)
Call all of the after callbacks with check result.
at line 346
protected callable
resolveAuthCallback(Authenticatable $user, string $ability, array $arguments)
Resolve the callable for the given ability and arguments.
at line 369
mixed
getPolicyFor(object|string $class)
Get a policy instance for a given class.
at line 396
mixed
resolvePolicy(object|string $class)
Build a policy class instance of the given type.
at line 410
protected callable
resolvePolicyCallback(Authenticatable $user, string $ability, array $arguments, mixed $policy)
Resolve the callback for a policy check.
at line 451
protected mixed
callPolicyBefore(mixed $policy, Authenticatable $user, string $ability, array $arguments)
Call the "before" method on the given policy, if applicable.
at line 464
protected string
formatAbilityToMethod(string $ability)
Format the policy ability into a method name.
at line 475
Gate
forUser(Authenticatable|mixed $user)
Get a gate instance for the given user.
at line 492
protected mixed
resolveUser()
Resolve the user from the user resolver.
at line 502
array
abilities()
Get all of the defined abilities.