class AccessToken extends AbstractModel

Constants

LAST_ACTIVITY_UPDATE_DIFF

Difference from the current `last_activity_at` attribute value before `updateLastSeen()` will update the attribute on the DB. Measured in seconds.

Properties

bool $timestamps Indicates if the model should be timestamped. Turn off by default. from AbstractModel
protected callable[] $afterSaveCallbacks An array of callbacks to be run once after the model is saved. from AbstractModel
protected callable[] $afterDeleteCallbacks An array of callbacks to be run once after the model is deleted. from AbstractModel
static $customRelations from AbstractModel
static $dateAttributes from AbstractModel
static $defaults from AbstractModel
protected $table
protected $dates
static protected array $models A map of access token types, as specified in the `type` column, to their classes.
string $type
static protected int $lifetime How long this access token should be valid from the time of last activity.
int $id
string $token
int $user_id
Carbon $created_at
Carbon|null $last_activity_at
string $title
string $last_ip_address
string $last_user_agent
User|null $user

Methods

static 
boot()

{@inheritdoc}

__construct(array $attributes = [])

{@inheritdoc}

array
getDates()

Get the attributes that should be converted to dates.

mixed
getAttribute(string $key)

Get an attribute from the model. If nothing is found, attempt to load a custom relation method with this key.

mixed
getCustomRelation(string $name)

Get a custom relation object.

void
afterSave(callable $callback)

Register a callback to be run once after the model is saved.

void
afterDelete(callable $callback)

Register a callback to be run once after the model is deleted.

callable[]
releaseAfterSaveCallbacks()

No description

callable[]
releaseAfterDeleteCallbacks()

No description

__call($method, $arguments)

{@inheritdoc}

static AccessToken
generate(int $userId)

Generate an access token for the specified user.

bool
touch(ServerRequestInterface $request = null)

Update the time of last usage of a token.

BelongsTo
user()

Define the relationship with the owner of this access token.

static 
scopeValid(Builder $query, Carbon $date)

Filters which tokens are valid at the given date for this particular token type.

static 
scopeExpired(Builder $query, Carbon $date)

Filters which tokens are expired at the given date and ready for garbage collection.

static AccessToken|null
findValid(string $token)

Shortcut to find a valid token.

scopeWhereValid(Builder $query, Carbon $date = null)

This query scope is intended to be used on the base AccessToken object to query for valid tokens of any type.

scopeWhereExpired(Builder $query, Carbon $date = null)

This query scope is intended to be used on the base AccessToken object to query for expired tokens of any type.

AccessToken|object
newFromBuilder(array $attributes = [], string|null $connection = null)

Create a new model instance according to the access token type.

static array
getModels()

Get the type-to-model map.

static void
setModel(string $type, string $model)

Set the model for the given access token type.

Details

static boot()

{@inheritdoc}

__construct(array $attributes = [])

{@inheritdoc}

Parameters

array $attributes

array getDates()

Get the attributes that should be converted to dates.

Return Value

array

mixed getAttribute(string $key)

Get an attribute from the model. If nothing is found, attempt to load a custom relation method with this key.

Parameters

string $key

Return Value

mixed

protected mixed getCustomRelation(string $name)

Get a custom relation object.

Parameters

string $name

Return Value

mixed

void afterSave(callable $callback)

Register a callback to be run once after the model is saved.

Parameters

callable $callback

Return Value

void

void afterDelete(callable $callback)

Register a callback to be run once after the model is deleted.

Parameters

callable $callback

Return Value

void

callable[] releaseAfterSaveCallbacks()

Return Value

callable[]

callable[] releaseAfterDeleteCallbacks()

Return Value

callable[]

__call($method, $arguments)

{@inheritdoc}

Parameters

$method
$arguments

static AccessToken generate(int $userId)

Generate an access token for the specified user.

Parameters

int $userId

Return Value

AccessToken

bool touch(ServerRequestInterface $request = null)

Update the time of last usage of a token.

If a request object is provided, the IP address and User Agent will also be logged.

Parameters

ServerRequestInterface $request

Return Value

bool

BelongsTo user()

Define the relationship with the owner of this access token.

Return Value

BelongsTo

static protected scopeValid(Builder $query, Carbon $date)

Filters which tokens are valid at the given date for this particular token type.

Uses the static::$lifetime value by default, can be overridden by children classes.

Parameters

Builder $query
Carbon $date

static protected scopeExpired(Builder $query, Carbon $date)

Filters which tokens are expired at the given date and ready for garbage collection.

Uses the static::$lifetime value by default, can be overridden by children classes.

Parameters

Builder $query
Carbon $date

static AccessToken|null findValid(string $token)

Shortcut to find a valid token.

Parameters

string $token Token as sent by the user. We allow non-string values like null so we can directly feed any value from a request.

Return Value

AccessToken|null

scopeWhereValid(Builder $query, Carbon $date = null)

This query scope is intended to be used on the base AccessToken object to query for valid tokens of any type.

Parameters

Builder $query
Carbon $date

scopeWhereExpired(Builder $query, Carbon $date = null)

This query scope is intended to be used on the base AccessToken object to query for expired tokens of any type.

Parameters

Builder $query
Carbon $date

AccessToken|object newFromBuilder(array $attributes = [], string|null $connection = null)

Create a new model instance according to the access token type.

Parameters

array $attributes
string|null $connection

Return Value

AccessToken|object

static array getModels()

Get the type-to-model map.

Return Value

array

static void setModel(string $type, string $model)

Set the model for the given access token type.

Parameters

string $type The access token type.
string $model The class name of the model for that type.

Return Value

void