class Illuminate / Auth / Access / Gate
You are viewing an older version of the documentation. For the latest, please visit master documentation.

Gate

Implements

Uses

Properties

protected

$container Container

The container instance.

Default: null
protected

$userResolver callable

The user resolver callable.

Default: null
protected

$abilities array

All of the defined abilities.

Default: []
protected

$policies array

All of the defined policies.

Default: []
protected

$beforeCallbacks array

All of the registered before callbacks.

Default: []
protected

$afterCallbacks array

All of the registered after callbacks.

Default: []
protected

$stringCallbacks array

All of the defined abilities using class@method notation.

Default: []
protected

$guessPolicyNamesUsingCallback callable|null

The callback to be used to guess policy names.

Default: null

Methods

public

__construct ( Container $container , callable $userResolver , array $abilities , array $policies , array $beforeCallbacks , array $afterCallbacks , callable $guessPolicyNamesUsingCallback ) : void

Create a new gate instance.

Parameters

  • $container Container
  • $userResolver callable
  • $abilities array
  • $policies array
  • $beforeCallbacks array
  • $afterCallbacks array
  • $guessPolicyNamesUsingCallback callable|null
public

has ( $ability ) : bool

Determine if a given ability has been defined.

Parameters

  • $ability string|array
public

allowIf ( $condition , $message , $code ) : Response

Perform an on-demand authorization check. Throw an authorization exception if the condition or callback is false.

Parameters

public

denyIf ( $condition , $message , $code ) : Response

Perform an on-demand authorization check. Throw an authorization exception if the condition or callback is true.

Parameters

protected

authorizeOnDemand ( $condition , $message , $code , $allowWhenResponseIs ) : Response

Authorize a given condition or callback.

Parameters

  • $condition Response |Closure |bool
  • $message string|null
  • $code string|null
  • $allowWhenResponseIs bool
public

define ( $ability , $callback ) : $this

Define a new ability.

Parameters

  • $ability string
  • $callback callable|string
public

resource ( $name , $class , array $abilities ) : $this

Define abilities for a resource.

Parameters

  • $name string
  • $class string
  • $abilities array|null
protected

buildAbilityCallback ( $ability , $callback ) : Closure

Create the ability callback for a callback string.

Parameters

  • $ability string
  • $callback string
public

policy ( $class , $policy ) : $this

Define a policy class for a given class type.

Parameters

  • $class string
  • $policy string
public

before ( callable $callback ) : $this

Register a callback to run before all Gate checks.

Parameters

  • $callback callable
public

after ( callable $callback ) : $this

Register a callback to run after all Gate checks.

Parameters

  • $callback callable
public

allows ( $ability , $arguments ) : bool

Determine if the given ability should be granted for the current user.

Parameters

  • $ability string
  • $arguments array|mixed
public

denies ( $ability , $arguments ) : bool

Determine if the given ability should be denied for the current user.

Parameters

  • $ability string
  • $arguments array|mixed
public

check ( $abilities , $arguments ) : bool

Determine if all of the given abilities should be granted for the current user.

Parameters

  • $abilities iterable|string
  • $arguments array|mixed
public

any ( $abilities , $arguments ) : bool

Determine if any one of the given abilities should be granted for the current user.

Parameters

  • $abilities iterable|string
  • $arguments array|mixed
public

none ( $abilities , $arguments ) : bool

Determine if all of the given abilities should be denied for the current user.

Parameters

  • $abilities iterable|string
  • $arguments array|mixed
public

authorize ( $ability , $arguments ) : Response

Determine if the given ability should be granted for the current user.

Parameters

  • $ability string
  • $arguments array|mixed
public

inspect ( $ability , $arguments ) : Response

Inspect the user for the given ability.

Parameters

  • $ability string
  • $arguments array|mixed
public

raw ( $ability , $arguments ) : mixed

Get the raw result from the authorization callback.

Parameters

  • $ability string
  • $arguments array|mixed
protected

canBeCalledWithUser ( $user , $class , $method ) : bool

Determine whether the callback/method can be called with the given user.

Parameters

protected

methodAllowsGuests ( $class , $method ) : bool

Determine if the given class method allows guests.

Parameters

  • $class string
  • $method string
protected

callbackAllowsGuests ( $callback ) : bool

Determine if the callback allows guests.

Parameters

  • $callback callable
protected

parameterAllowsGuests ( $parameter ) : bool

Determine if the given parameter allows guests.

Parameters

protected

callAuthCallback ( $user , $ability , array $arguments ) : bool

Resolve and call the appropriate authorization callback.

Parameters

protected

callBeforeCallbacks ( $user , $ability , array $arguments ) : bool|null

Call all of the before callbacks and return if a result is given.

Parameters

protected

callAfterCallbacks ( $user , $ability , array $arguments , $result ) : bool|null

Call all of the after callbacks with check result.

Parameters

protected

dispatchGateEvaluatedEvent ( $user , $ability , array $arguments , $result ) : void

Dispatch a gate evaluation event.

Parameters

  • $user Authenticatable |null
  • $ability string
  • $arguments array
  • $result bool|null
protected

resolveAuthCallback ( $user , $ability , array $arguments ) : callable

Resolve the callable for the given ability and arguments.

Parameters

public

getPolicyFor ( $class ) : mixed

Get a policy instance for a given class.

Parameters

  • $class object|string
protected

guessPolicyName ( $class ) : array

Guess the policy name for the given class.

Parameters

  • $class string
public

guessPolicyNamesUsing ( callable $callback ) : $this

Specify a callback to be used to guess policy names.

Parameters

  • $callback callable
public

resolvePolicy ( $class ) : mixed

Build a policy class instance of the given type.

Parameters

  • $class object|string
protected

resolvePolicyCallback ( $user , $ability , array $arguments , $policy ) : bool|callable

Resolve the callback for a policy check.

Parameters

protected

callPolicyBefore ( $policy , $user , $ability , $arguments ) : mixed

Call the "before" method on the given policy, if applicable.

Parameters

protected

callPolicyMethod ( $policy , $method , $user , array $arguments ) : mixed

Call the appropriate method on the given policy.

Parameters

protected

formatAbilityToMethod ( $ability ) : string

Format the policy ability into a method name.

Parameters

  • $ability string
public

forUser ( $user ) : static

Get a gate instance for the given user.

Parameters

protected

resolveUser ( ) : mixed

Resolve the user from the user resolver.

public

abilities ( ) : array

Get all of the defined abilities.

public

policies ( ) : array

Get all of the defined policies.

public

setContainer ( Container $container ) : $this

Set the container instance used by the gate.

Parameters