Gate
class Gate implements Gate (View source)
Traits
HandlesAuthorization |
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
Response | allow(string|null $message = null) Create a new access response. | from HandlesAuthorization |
void | deny(string $message = 'This action is unauthorized.') Throws an unauthorized exception. | from HandlesAuthorization |
void | __construct(Container $container, callable $userResolver, array $abilities = [], array $policies = [], array $beforeCallbacks = [], array $afterCallbacks = []) Create a new gate instance. | |
bool | has(string $ability) Determine if a given ability has been defined. | |
$this | define(string $ability, callable|string $callback) Define a new ability. | |
Closure | buildAbilityCallback(string $callback) Create the ability callback for a callback string. | |
$this | policy(string $class, string $policy) Define a policy class for a given class type. | |
$this | before(callable $callback) Register a callback to run before all Gate checks. | |
$this | after(callable $callback) Register a callback to run after all Gate checks. | |
bool | allows(string $ability, array|mixed $arguments = []) Determine if the given ability should be granted for the current user. | |
bool | denies(string $ability, array|mixed $arguments = []) Determine if the given ability should be denied for the current user. | |
bool | check(string $ability, array|mixed $arguments = []) Determine if the given ability should be granted for the current user. | |
Response | authorize(string $ability, array|mixed $arguments = []) Determine if the given ability should be granted for the current user. | |
mixed | raw(string $ability, array|mixed $arguments = []) Get the raw result for the given ability for the current user. | |
bool | callAuthCallback(Authenticatable $user, string $ability, array $arguments) Resolve and call the appropriate authorization callback. | |
bool|null | callBeforeCallbacks(Authenticatable $user, string $ability, array $arguments) Call all of the before callbacks and return if a result is given. | |
void | callAfterCallbacks(Authenticatable $user, string $ability, array $arguments, bool $result) Call all of the after callbacks with check result. | |
callable | resolveAuthCallback(Authenticatable $user, string $ability, array $arguments) Resolve the callable for the given ability and arguments. | |
bool | firstArgumentCorrespondsToPolicy(array $arguments) Determine if the first argument in the array corresponds to a policy. | |
callable | resolvePolicyCallback(Authenticatable $user, string $ability, array $arguments) Resolve the callback for a policy check. | |
mixed | getPolicyFor(object|string $class) Get a policy instance for a given class. | |
mixed | resolvePolicy(object|string $class) Build a policy class instance of the given type. | |
Gate | forUser(Authenticatable|mixed $user) Get a gate instance for the given user. | |
mixed | resolveUser() Resolve the user from the user resolver. |
Details
protected Response allow(string|null $message = null)
Create a new access response.
protected void deny(string $message = 'This action is unauthorized.')
Throws an unauthorized exception.
void __construct(Container $container, callable $userResolver, array $abilities = [], array $policies = [], array $beforeCallbacks = [], array $afterCallbacks = [])
Create a new gate instance.
bool has(string $ability)
Determine if a given ability has been defined.
$this define(string $ability, callable|string $callback)
Define a new ability.
protected Closure buildAbilityCallback(string $callback)
Create the ability callback for a callback string.
$this policy(string $class, string $policy)
Define a policy class for a given class type.
$this before(callable $callback)
Register a callback to run before all Gate checks.
$this after(callable $callback)
Register a callback to run after all Gate checks.
bool allows(string $ability, array|mixed $arguments = [])
Determine if the given ability should be granted for the current user.
bool denies(string $ability, array|mixed $arguments = [])
Determine if the given ability should be denied for the current user.
bool check(string $ability, array|mixed $arguments = [])
Determine if the given ability should be granted for the current user.
Response authorize(string $ability, array|mixed $arguments = [])
Determine if the given ability should be granted for the current user.
protected mixed raw(string $ability, array|mixed $arguments = [])
Get the raw result for the given ability for the current user.
protected bool callAuthCallback(Authenticatable $user, string $ability, array $arguments)
Resolve and call the appropriate authorization callback.
protected bool|null callBeforeCallbacks(Authenticatable $user, string $ability, array $arguments)
Call all of the before callbacks and return if a result is given.
protected void callAfterCallbacks(Authenticatable $user, string $ability, array $arguments, bool $result)
Call all of the after callbacks with check result.
protected callable resolveAuthCallback(Authenticatable $user, string $ability, array $arguments)
Resolve the callable for the given ability and arguments.
protected bool firstArgumentCorrespondsToPolicy(array $arguments)
Determine if the first argument in the array corresponds to a policy.
protected callable resolvePolicyCallback(Authenticatable $user, string $ability, array $arguments)
Resolve the callback for a policy check.
mixed getPolicyFor(object|string $class)
Get a policy instance for a given class.
mixed resolvePolicy(object|string $class)
Build a policy class instance of the given type.
Gate forUser(Authenticatable|mixed $user)
Get a gate instance for the given user.
protected mixed resolveUser()
Resolve the user from the user resolver.
© Taylor Otwell
Licensed under the MIT License.
Laravel is a trademark of Taylor Otwell.
https://laravel.com/api/5.3/Illuminate/Auth/Access/Gate.html