class Gate implements Gate

Properties

protected Container $container <p>The container instance.</p>
protected callable $userResolver <p>The user resolver callable.</p>
protected array $abilities <p>All of the defined abilities.</p>
protected array $policies <p>All of the defined policies.</p>
protected array $beforeCallbacks <p>All of the registered before callbacks.</p>

Methods

void
__construct(Container $container, callable $userResolver, array $abilities = [], array $policies = [], array $beforeCallbacks = [])

<p>Create a new gate instance.</p>

bool
has(string $ability)

<p>Determine if a given ability has been defined.</p>

$this
define(string $ability, callable|string $callback)

<p>Define a new ability.</p>

buildAbilityCallback(string $callback)

<p>Create the ability callback for a callback string.</p>

$this
policy(string $class, string $policy)

<p>Define a policy class for a given class type.</p>

$this
before(callable $callback)

<p>Register a callback to run before all Gate checks.</p>

bool
allows(string $ability, array|mixed $arguments = [])

<p>Determine if the given ability should be granted for the current user.</p>

bool
denies(string $ability, array|mixed $arguments = [])

<p>Determine if the given ability should be denied for the current user.</p>

bool
check(string $ability, array|mixed $arguments = [])

<p>Determine if the given ability should be granted for the current user.</p>

bool|void
callBeforeCallbacks(Authenticatable $user, string $ability, array $arguments)

<p>Call all of the before callbacks and return if a result is given.</p>

callable
resolveAuthCallback(Authenticatable $user, string $ability, array $arguments)

<p>Resolve the callable for the given ability and arguments.</p>

bool
firstArgumentCorrespondsToPolicy(array $arguments)

<p>Determine if the first argument in the array corresponds to a policy.</p>

callable
resolvePolicyCallback(Authenticatable $user, string $ability, array $arguments)

<p>Resolve the callback for a policy check.</p>

mixed
getPolicyFor(object|string $class)

<p>Get a policy instance for a given class.</p>

mixed
resolvePolicy(object|string $class)

<p>Build a policy class instance of the given type.</p>

forUser(Authenticatable|mixed $user)

<p>Get a guard instance for the given user.</p>

mixed
resolveUser()

<p>Resolve the user from the user resolver.</p>

Gate
after(callable $callback)

<p>Register a callback to run after all Gate checks.</p>

bool
any(iterable|string $abilities, array|mixed $arguments = [])

<p>Determine if any one of the given abilities should be granted for the current user.</p>

Response
authorize(string $ability, array|mixed $arguments = [])

<p>Determine if the given ability should be granted for the current user.</p>

array
abilities()

<p>Get all of the defined abilities.</p>

mixed
raw(string $ability, array|mixed $arguments = [])

<p>Get the raw result from the authorization callback.</p>

Details

void __construct(Container $container, callable $userResolver, array $abilities = [], array $policies = [], array $beforeCallbacks = [])

<p>Create a new gate instance.</p>

Parameters

Container $container
callable $userResolver
array $abilities
array $policies
array $beforeCallbacks

Return Value

void

bool has(string $ability)

<p>Determine if a given ability has been defined.</p>

Parameters

string $ability

Return Value

bool

$this define(string $ability, callable|string $callback)

<p>Define a new ability.</p>

Parameters

string $ability
callable|string $callback

Return Value

$this

Exceptions

InvalidArgumentException

protected Closure buildAbilityCallback(string $callback)

<p>Create the ability callback for a callback string.</p>

Parameters

string $callback

Return Value

Closure

$this policy(string $class, string $policy)

<p>Define a policy class for a given class type.</p>

Parameters

string $class
string $policy

Return Value

$this

$this before(callable $callback)

<p>Register a callback to run before all Gate checks.</p>

Parameters

callable $callback

Return Value

$this

bool allows(string $ability, array|mixed $arguments = [])

<p>Determine if the given ability should be granted for the current user.</p>

Parameters

string $ability
array|mixed $arguments

Return Value

bool

bool denies(string $ability, array|mixed $arguments = [])

<p>Determine if the given ability should be denied for the current user.</p>

Parameters

string $ability
array|mixed $arguments

Return Value

bool

bool check(string $ability, array|mixed $arguments = [])

<p>Determine if the given ability should be granted for the current user.</p>

Parameters

string $ability
array|mixed $arguments

Return Value

bool

protected bool|void callBeforeCallbacks(Authenticatable $user, string $ability, array $arguments)

<p>Call all of the before callbacks and return if a result is given.</p>

Parameters

Authenticatable $user
string $ability
array $arguments

Return Value

bool|void

protected callable resolveAuthCallback(Authenticatable $user, string $ability, array $arguments)

<p>Resolve the callable for the given ability and arguments.</p>

Parameters

Authenticatable $user
string $ability
array $arguments

Return Value

callable

protected bool firstArgumentCorrespondsToPolicy(array $arguments)

<p>Determine if the first argument in the array corresponds to a policy.</p>

Parameters

array $arguments

Return Value

bool

protected callable resolvePolicyCallback(Authenticatable $user, string $ability, array $arguments)

<p>Resolve the callback for a policy check.</p>

Parameters

Authenticatable $user
string $ability
array $arguments

Return Value

callable

mixed getPolicyFor(object|string $class)

<p>Get a policy instance for a given class.</p>

Parameters

object|string $class

Return Value

mixed

Exceptions

InvalidArgumentException

mixed resolvePolicy(object|string $class)

<p>Build a policy class instance of the given type.</p>

Parameters

object|string $class

Return Value

mixed

Gate forUser(Authenticatable|mixed $user)

<p>Get a guard instance for the given user.</p>

Parameters

Authenticatable|mixed $user

Return Value

Gate

protected mixed resolveUser()

<p>Resolve the user from the user resolver.</p>

Return Value

mixed

Gate after(callable $callback)

<p>Register a callback to run after all Gate checks.</p>

Parameters

callable $callback

Return Value

Gate

bool any(iterable|string $abilities, array|mixed $arguments = [])

<p>Determine if any one of the given abilities should be granted for the current user.</p>

Parameters

iterable|string $abilities
array|mixed $arguments

Return Value

bool

Response authorize(string $ability, array|mixed $arguments = [])

<p>Determine if the given ability should be granted for the current user.</p>

Parameters

string $ability
array|mixed $arguments

Return Value

Response

Exceptions

AuthorizationException

array abilities()

<p>Get all of the defined abilities.</p>

Return Value

array

mixed raw(string $ability, array|mixed $arguments = [])

<p>Get the raw result from the authorization callback.</p>

Parameters

string $ability
array|mixed $arguments

Return Value

mixed