master

laravel/framework

Last updated at: 29/12/2023 09:25

Gate.php

TLDR

The Gate.php file is a part of the Illuminate\Support\Facades namespace. It contains a Facade class called Gate that provides static methods for accessing the GateContract interface. The Gate facade allows for defining and checking authorization abilities in Laravel applications.

Methods

has

Checks if the gate contains the given ability.

allowIf

Adds an "allow" condition to the given callback or condition. If the condition is met, it allows access to the ability.

denyIf

Adds a "deny" condition to the given callback or condition. If the condition is met, it denies access to the ability.

define

Defines a new ability callback.

resource

Defines the abilities for a resource.

policy

Registers a policy callback for the given class.

before

Adds a callback to be run before all other authorization checks.

after

Adds a callback to be run after all other authorization checks.

allows

Checks if the access is allowed for the given ability and arguments.

denies

Checks if the access is denied for the given ability and arguments.

check

Checks if any of the provided abilities pass the authorization check.

any

Checks if any of the provided abilities pass the authorization check.

none

Checks if none of the provided abilities pass the authorization check.

authorize

Authorizes the given ability and arguments.

inspect

Inspects the ability and arguments to check if it is authorized.

raw

Gets the raw result from the gate for the given ability and arguments.

getPolicyFor

Returns the policy instance for the given class.

guessPolicyNamesUsing

Sets a callback to guess the policy names.

resolvePolicy

Resolves the policy instance for the given class.

forUser

Sets the user for whom the authorization checks will be performed.

abilities

Gets all of the defined abilities.

policies

Gets all of the registered policies.

defaultDenialResponse

Sets the default response returned when access is denied.

setContainer

Sets the container instance for the gate.

denyWithStatus

Deny access with the specified status, message, and code.

denyAsNotFound

Deny access as "not found" with the specified message and code.

Classes

No additional classes in this file.

<?php

namespace Illuminate\Support\Facades;

use Illuminate\Contracts\Auth\Access\Gate as GateContract;

/**
 * @method static bool has(string|array $ability)
 * @method static \Illuminate\Auth\Access\Response allowIf(\Illuminate\Auth\Access\Response|\Closure|bool $condition, string|null $message = null, string|null $code = null)
 * @method static \Illuminate\Auth\Access\Response denyIf(\Illuminate\Auth\Access\Response|\Closure|bool $condition, string|null $message = null, string|null $code = null)
 * @method static \Illuminate\Auth\Access\Gate define(string $ability, callable|array|string $callback)
 * @method static \Illuminate\Auth\Access\Gate resource(string $name, string $class, array|null $abilities = null)
 * @method static \Illuminate\Auth\Access\Gate policy(string $class, string $policy)
 * @method static \Illuminate\Auth\Access\Gate before(callable $callback)
 * @method static \Illuminate\Auth\Access\Gate after(callable $callback)
 * @method static bool allows(string $ability, array|mixed $arguments = [])
 * @method static bool denies(string $ability, array|mixed $arguments = [])
 * @method static bool check(iterable|string $abilities, array|mixed $arguments = [])
 * @method static bool any(iterable|string $abilities, array|mixed $arguments = [])
 * @method static bool none(iterable|string $abilities, array|mixed $arguments = [])
 * @method static \Illuminate\Auth\Access\Response authorize(string $ability, array|mixed $arguments = [])
 * @method static \Illuminate\Auth\Access\Response inspect(string $ability, array|mixed $arguments = [])
 * @method static mixed raw(string $ability, array|mixed $arguments = [])
 * @method static mixed getPolicyFor(object|string $class)
 * @method static \Illuminate\Auth\Access\Gate guessPolicyNamesUsing(callable $callback)
 * @method static mixed resolvePolicy(object|string $class)
 * @method static \Illuminate\Auth\Access\Gate forUser(\Illuminate\Contracts\Auth\Authenticatable|mixed $user)
 * @method static array abilities()
 * @method static array policies()
 * @method static \Illuminate\Auth\Access\Gate defaultDenialResponse(\Illuminate\Auth\Access\Response $response)
 * @method static \Illuminate\Auth\Access\Gate setContainer(\Illuminate\Contracts\Container\Container $container)
 * @method static \Illuminate\Auth\Access\Response denyWithStatus(int $status, string|null $message = null, int|null $code = null)
 * @method static \Illuminate\Auth\Access\Response denyAsNotFound(string|null $message = null, int|null $code = null)
 *
 * @see \Illuminate\Auth\Access\Gate
 */
class Gate extends Facade
{
    /**
     * Get the registered name of the component.
     *
     * @return string
     */
    protected static function getFacadeAccessor()
    {
        return GateContract::class;
    }
}