interface Gate

Methods

bool
has(array|UnitEnum|string $ability)

Determine if a given ability has been defined.

define(UnitEnum|string $ability, array|callable|string $callback)

Define a new ability.

resource(string $name, string $class, array|null $abilities = null)

Define abilities for a resource.

policy(string $class, string $policy)

Define a policy class for a given class type.

before(callable $callback)

Register a callback to run before all Gate checks.

after(callable $callback)

Register a callback to run after all Gate checks.

allowIf(mixed $condition, string|null $message = null, int|string|null $code = null)

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

denyIf(mixed $condition, string|null $message = null, int|string|null $code = null)

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

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

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

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

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

bool
check(iterable|UnitEnum|string $abilities, mixed $arguments = [])

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

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

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

bool
none(iterable|UnitEnum|string $abilities, mixed $arguments = [])

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

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

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

inspect(UnitEnum|string $ability, mixed $arguments = [])

Inspect the user for the given ability.

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

Get the raw result from the authorization callback.

scope(UnitEnum|string $ability, Builder $query)

Apply the policy's scope method to filter a query to authorized rows.

select(UnitEnum|string $ability, Builder|Model|string $query)

Get a scalar boolean selection from the policy for per-row authorization.

mixed
getPolicyFor(object|string $class)

Get a policy instance for a given class.

forUser(mixed $user)

Get a gate instance for the given user.

array
abilities()

Get all of the defined abilities.

Details

at line 23
bool has(array|UnitEnum|string $ability)

Determine if a given ability has been defined.

Parameters

array|UnitEnum|string $ability

Return Value

bool

at line 30
Gate define(UnitEnum|string $ability, array|callable|string $callback)

Define a new ability.

Parameters

UnitEnum|string $ability
array|callable|string $callback

Return Value

Gate

Exceptions

InvalidArgumentException

at line 35
Gate resource(string $name, string $class, array|null $abilities = null)

Define abilities for a resource.

Parameters

string $name
string $class
array|null $abilities

Return Value

Gate

at line 40
Gate policy(string $class, string $policy)

Define a policy class for a given class type.

Parameters

string $class
string $policy

Return Value

Gate

at line 45
Gate before(callable $callback)

Register a callback to run before all Gate checks.

Parameters

callable $callback

Return Value

Gate

at line 50
Gate after(callable $callback)

Register a callback to run after all Gate checks.

Parameters

callable $callback

Return Value

Gate

at line 57
Response allowIf(mixed $condition, string|null $message = null, int|string|null $code = null)

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

Parameters

mixed $condition
string|null $message
int|string|null $code

Return Value

Response

Exceptions

AuthorizationException

at line 64
Response denyIf(mixed $condition, string|null $message = null, int|string|null $code = null)

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

Parameters

mixed $condition
string|null $message
int|string|null $code

Return Value

Response

Exceptions

AuthorizationException

at line 69
bool allows(iterable|UnitEnum|string $ability, mixed $arguments = [])

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

Parameters

iterable|UnitEnum|string $ability
mixed $arguments

Return Value

bool

at line 74
bool denies(iterable|UnitEnum|string $ability, mixed $arguments = [])

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

Parameters

iterable|UnitEnum|string $ability
mixed $arguments

Return Value

bool

at line 79
bool check(iterable|UnitEnum|string $abilities, mixed $arguments = [])

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

Parameters

iterable|UnitEnum|string $abilities
mixed $arguments

Return Value

bool

at line 84
bool any(iterable|UnitEnum|string $abilities, mixed $arguments = [])

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

Parameters

iterable|UnitEnum|string $abilities
mixed $arguments

Return Value

bool

at line 89
bool none(iterable|UnitEnum|string $abilities, mixed $arguments = [])

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

Parameters

iterable|UnitEnum|string $abilities
mixed $arguments

Return Value

bool

at line 96
Response authorize(UnitEnum|string $ability, mixed $arguments = [])

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

Parameters

UnitEnum|string $ability
mixed $arguments

Return Value

Response

Exceptions

AuthorizationException

at line 101
Response inspect(UnitEnum|string $ability, mixed $arguments = [])

Inspect the user for the given ability.

Parameters

UnitEnum|string $ability
mixed $arguments

Return Value

Response

at line 108
mixed raw(string $ability, mixed $arguments = [])

Get the raw result from the authorization callback.

Parameters

string $ability
mixed $arguments

Return Value

mixed

Exceptions

AuthorizationException

at line 116
Builder scope(UnitEnum|string $ability, Builder $query)

Apply the policy's scope method to filter a query to authorized rows.

Parameters

UnitEnum|string $ability
Builder $query

Return Value

Builder

Exceptions

LogicException
RuntimeException

at line 126
Expression|Builder select(UnitEnum|string $ability, Builder|Model|string $query)

Get a scalar boolean selection from the policy for per-row authorization.

Parameters

UnitEnum|string $ability
Builder|Model|string $query

Return Value

Expression|Builder

Exceptions

LogicException
RuntimeException

at line 131
mixed getPolicyFor(object|string $class)

Get a policy instance for a given class.

Parameters

object|string $class

Return Value

mixed

at line 136
Gate forUser(mixed $user)

Get a gate instance for the given user.

Parameters

mixed $user

Return Value

Gate

at line 141
array abilities()

Get all of the defined abilities.

Return Value

array