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(string $ability, Builder $query)

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

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

Get a SQL expression 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 21
bool has(array|UnitEnum|string $ability)

Determine if a given ability has been defined.

Parameters

array|UnitEnum|string $ability

Return Value

bool

at line 28
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 33
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 38
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 43
Gate before(callable $callback)

Register a callback to run before all Gate checks.

Parameters

callable $callback

Return Value

Gate

at line 48
Gate after(callable $callback)

Register a callback to run after all Gate checks.

Parameters

callable $callback

Return Value

Gate

at line 55
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 62
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 67
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 72
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 77
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 82
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 87
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 94
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 99
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 106
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 113
Builder scope(string $ability, Builder $query)

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

Parameters

string $ability
Builder $query

Return Value

Builder

Exceptions

RuntimeException

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

Get a SQL expression from the policy for per-row authorization.

Parameters

string $ability
Builder|Model|string $query

Return Value

Expression

Exceptions

RuntimeException

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

Get a policy instance for a given class.

Parameters

object|string $class

Return Value

mixed

at line 132
Gate forUser(mixed $user)

Get a gate instance for the given user.

Parameters

mixed $user

Return Value

Gate

at line 137
array abilities()

Get all of the defined abilities.

Return Value

array