class TokenGuard implements Guard (View source)

Traits

These methods are typically the same across all guards.

Properties

protected Authenticatable|null $user

The currently authenticated user.

from  GuardHelpers
protected UserProvider $provider

The user provider implementation.

from  GuardHelpers
static protected array $macros

The registered string macros.

from  Macroable
protected Request $request

The request instance.

protected string $inputKey

The name of the query string item from the request containing the API token.

protected string $storageKey

The name of the token "column" in persistent storage.

protected bool $hash

Indicates if the API token is hashed in storage.

Methods

authenticate()

Determine if the current user is authenticated. If not, throw an exception.

bool
hasUser()

Determine if the guard has a user instance.

bool
check()

Determine if the current user is authenticated.

bool
guest()

Determine if the current user is a guest.

int|string|null
id()

Get the ID for the currently authenticated user.

$this
setUser(Authenticatable $user)

Set the current user.

$this
forgetUser()

Forget the current user.

getProvider()

Get the user provider used by the guard.

void
setProvider(UserProvider $provider)

Set the user provider used by the guard.

static void
macro(string $name, object|callable $macro)

Register a custom macro.

static void
mixin(object $mixin, bool $replace = true)

Mix another object into the class.

static bool
hasMacro(string $name)

Checks if macro is registered.

static void
flushMacros()

Flush the existing macros.

static mixed
__callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

mixed
__call(string $method, array $parameters)

Dynamically handle calls to the class.

void
__construct(UserProvider $provider, Request $request, string $inputKey = 'api_token', string $storageKey = 'api_token', bool $hash = false)

Create a new authentication guard.

user()

Get the currently authenticated user.

string|null
getTokenForRequest()

Get the token for the current request.

bool
validate(array $credentials = [])

Validate a user's credentials.

$this
setRequest(Request $request)

Set the current request instance.

Details

Authenticatable authenticate()

Determine if the current user is authenticated. If not, throw an exception.

Return Value

Authenticatable

Exceptions

AuthenticationException

bool hasUser()

Determine if the guard has a user instance.

Return Value

bool

bool check()

Determine if the current user is authenticated.

Return Value

bool

bool guest()

Determine if the current user is a guest.

Return Value

bool

int|string|null id()

Get the ID for the currently authenticated user.

Return Value

int|string|null

$this setUser(Authenticatable $user)

Set the current user.

Parameters

Authenticatable $user

Return Value

$this

$this forgetUser()

Forget the current user.

Return Value

$this

UserProvider getProvider()

Get the user provider used by the guard.

Return Value

UserProvider

void setProvider(UserProvider $provider)

Set the user provider used by the guard.

Parameters

UserProvider $provider

Return Value

void

static void macro(string $name, object|callable $macro)

Register a custom macro.

Parameters

string $name
object|callable $macro

Return Value

void

static void mixin(object $mixin, bool $replace = true)

Mix another object into the class.

Parameters

object $mixin
bool $replace

Return Value

void

Exceptions

ReflectionException

static bool hasMacro(string $name)

Checks if macro is registered.

Parameters

string $name

Return Value

bool

static void flushMacros()

Flush the existing macros.

Return Value

void

static mixed __callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

mixed __call(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

void __construct(UserProvider $provider, Request $request, string $inputKey = 'api_token', string $storageKey = 'api_token', bool $hash = false)

Create a new authentication guard.

Parameters

UserProvider $provider
Request $request
string $inputKey
string $storageKey
bool $hash

Return Value

void

Authenticatable|null user()

Get the currently authenticated user.

Return Value

Authenticatable|null

string|null getTokenForRequest()

Get the token for the current request.

Return Value

string|null

bool validate(array $credentials = [])

Validate a user's credentials.

Parameters

array $credentials

Return Value

bool

$this setRequest(Request $request)

Set the current request instance.

Parameters

Request $request

Return Value

$this