class Guest extends User

Traits

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 array $pendingEvents from EventGeneratorTrait
protected array $dates The attributes that should be mutated to dates. from User
protected string[]|null $permissions An array of permissions that this user has. from User
protected Session $session from User
static protected $groupProcessors An array of callables, through each of which the user's list of groups is passed before being returned. from User
array $preferences from User
static protected DriverInterface $displayNameDriver A driver for getting display names. from User
static protected Hasher $hasher The hasher with which to hash passwords. from User
static protected Gate $gate The access gate. from User
int $id Override the ID of this user, as a guest does not have an ID.
string $username from User
string $display_name from User
string $email from User
bool $is_email_confirmed from User
string $password from User
string|null $avatar_url from User
Carbon|null $joined_at from User
Carbon|null $last_seen_at from User
Carbon|null $marked_all_as_read_at from User
Carbon|null $read_notifications_at from User
int $discussion_count from User
int $comment_count from User

Methods

static 
boot()

Boot the model.

from User
__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}

raise(mixed $event)

Raise a new event.

array
releaseEvents()

Return and reset all pending events.

scopeWhereVisibleTo(Builder $query, User $actor)

Scope a query to only include records that are visible to a user.

static User
register(string $username, string $email, string $password)

Register a new user.

from User
static 
setGate(Gate $gate)

No description

from User
static 
setDisplayNameDriver(DriverInterface $driver)

Set the display name driver.

from User
$this
rename(string $username)

Rename the user.

from User
$this
changeEmail(string $email)

Change the user's email.

from User
$this
requestEmailChange(string $email)

Request that the user's email be changed.

from User
$this
changePassword(string $password)

Change the user's password.

from User
setPasswordAttribute(string $value)

Set the password attribute, storing it as a hash.

from User
$this
markAllAsRead()

Mark all discussions as read.

from User
$this
markNotificationsAsRead()

Mark all notifications as read.

from User
$this
changeAvatarPath(string $path)

Change the path of the user avatar.

from User
string
getAvatarUrlAttribute(string $value = null)

Get the URL of the user's avatar.

from User
string
getDisplayNameAttribute()

Get the user's display name.

from User
bool
checkPassword(string $password)

Check if a given password matches the user's password.

from User
$this
activate()

Activate the user's account.

from User
bool
hasPermission(string $permission)

Check whether the user has a certain permission based on their groups.

from User
bool
hasPermissionLike(string $match)

Check whether the user has a permission that is like the given string, based on their groups.

from User
array
getAlertableNotificationTypes()

Get the notification types that should be alerted to this user, according to their preferences.

from User
int
getUnreadNotificationCount()

Get the number of unread notifications for the user.

from User
Collection
getUnreadNotifications()

Get all notifications that have not been read yet.

from User
int
getNewNotificationCount()

Get the number of new, unseen notifications for the user.

from User
array
getPreferencesAttribute(string $value)

Get the values of all registered preferences for this user, by transforming their stored preferences and merging them with the defaults.

from User
setPreferencesAttribute(mixed $value)

Encode an array of preferences for storage in the database.

from User
bool
shouldAlert(string $type)

Check whether or not the user should receive an alert for a notification type.

from User
bool
shouldEmail(string $type)

Check whether or not the user should receive an email for a notification type.

from User
mixed
getPreference(string $key, mixed $default = null)

Get the value of a preference for this user.

from User
$this
setPreference(string $key, mixed $value)

Set the value of a preference for this user.

from User
$this
updateLastSeen()

Set the user as being last seen just now.

from User
bool
isAdmin()

Check whether or not the user is an administrator.

from User
bool
isGuest()

Check whether or not the user is a guest.

assertPermission(bool $condition)

Ensure the current user is allowed to do something.

from User
assertRegistered()

Ensure the given actor is authenticated.

from User
assertCan(string $ability, mixed $arguments = [])

No description

from User
assertAdmin()

No description

from User
HasMany
posts()

Define the relationship with the user's posts.

from User
HasMany
discussions()

Define the relationship with the user's discussions.

from User
BelongsTo
read()

Define the relationship with the user's read discussions.

from User
BelongsToMany
groups()

Define the relationship with the user's groups.

from User
visibleGroups()

No description

from User
HasMany
notifications()

Define the relationship with the user's notifications.

from User
HasMany
emailTokens()

Define the relationship with the user's email tokens.

from User
Builder
permissions()

Define the relationship with the permissions of all of the groups that the user is in.

from User
string[]
getPermissions()

Get a list of permissions that the user has.

from User
HasMany
accessTokens()

Define the relationship with the user's access tokens.

from User
loginProviders()

Get the user's login providers.

from User
bool
can(string $ability, array|mixed $arguments = [])

No description

from User
bool
cannot(string $ability, array|mixed $arguments = [])

No description

from User
Session
getSession()

No description

from User
setSession(Session $session)

No description

from User
static 
setHasher(Hasher $hasher)

Set the hasher with which to hash passwords.

from User
static 
addPreference(string $key, callable $transformer = null, mixed $default = null)

Register a preference with a transformer and a default value.

from User
static array
addGroupProcessor(callable $callback)

Register a callback that processes a user's list of groups.

from User
static string
getNotificationPreferenceKey(string $type, string $method)

Get the key for a preference which flags whether or not the user will receive a notification for $type via $method.

from User
$this
refreshCommentCount()

Refresh the user's comments count.

from User
$this
refreshDiscussionCount()

Refresh the user's comments count.

from User
getGroupsAttribute()

Get the guest's group, containing only the 'guests' group model.

Details

static boot()

Boot the model.

__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

raise(mixed $event)

Raise a new event.

Parameters

mixed $event

array releaseEvents()

Return and reset all pending events.

Return Value

array

scopeWhereVisibleTo(Builder $query, User $actor)

Scope a query to only include records that are visible to a user.

Parameters

Builder $query
User $actor

static User register(string $username, string $email, string $password)

Register a new user.

Parameters

string $username
string $email
string $password

Return Value

User

static setGate(Gate $gate)

Parameters

Gate $gate

static setDisplayNameDriver(DriverInterface $driver)

Set the display name driver.

Parameters

DriverInterface $driver

$this rename(string $username)

Rename the user.

Parameters

string $username

Return Value

$this

$this changeEmail(string $email)

Change the user's email.

Parameters

string $email

Return Value

$this

$this requestEmailChange(string $email)

Request that the user's email be changed.

Parameters

string $email

Return Value

$this

$this changePassword(string $password)

Change the user's password.

Parameters

string $password

Return Value

$this

setPasswordAttribute(string $value)

Set the password attribute, storing it as a hash.

Parameters

string $value

$this markAllAsRead()

Mark all discussions as read.

Return Value

$this

$this markNotificationsAsRead()

Mark all notifications as read.

Return Value

$this

$this changeAvatarPath(string $path)

Change the path of the user avatar.

Parameters

string $path

Return Value

$this

string getAvatarUrlAttribute(string $value = null)

Get the URL of the user's avatar.

Parameters

string $value

Return Value

string

string getDisplayNameAttribute()

Get the user's display name.

Return Value

string

bool checkPassword(string $password)

Check if a given password matches the user's password.

Parameters

string $password

Return Value

bool

$this activate()

Activate the user's account.

Return Value

$this

bool hasPermission(string $permission)

Check whether the user has a certain permission based on their groups.

Parameters

string $permission

Return Value

bool

bool hasPermissionLike(string $match)

Check whether the user has a permission that is like the given string, based on their groups.

Parameters

string $match

Return Value

bool

array getAlertableNotificationTypes()

Get the notification types that should be alerted to this user, according to their preferences.

Return Value

array

int getUnreadNotificationCount()

Get the number of unread notifications for the user.

Return Value

int

protected Collection getUnreadNotifications()

Get all notifications that have not been read yet.

Return Value

Collection

int getNewNotificationCount()

Get the number of new, unseen notifications for the user.

Return Value

int

array getPreferencesAttribute(string $value)

Get the values of all registered preferences for this user, by transforming their stored preferences and merging them with the defaults.

Parameters

string $value

Return Value

array

setPreferencesAttribute(mixed $value)

Encode an array of preferences for storage in the database.

Parameters

mixed $value

bool shouldAlert(string $type)

Check whether or not the user should receive an alert for a notification type.

Parameters

string $type

Return Value

bool

bool shouldEmail(string $type)

Check whether or not the user should receive an email for a notification type.

Parameters

string $type

Return Value

bool

mixed getPreference(string $key, mixed $default = null)

Get the value of a preference for this user.

Parameters

string $key
mixed $default

Return Value

mixed

$this setPreference(string $key, mixed $value)

Set the value of a preference for this user.

Parameters

string $key
mixed $value

Return Value

$this

$this updateLastSeen()

Set the user as being last seen just now.

Return Value

$this

bool isAdmin()

Check whether or not the user is an administrator.

Return Value

bool

bool isGuest()

Check whether or not the user is a guest.

Return Value

bool

assertPermission(bool $condition)

Ensure the current user is allowed to do something.

If the condition is not met, an exception will be thrown that signals the lack of permissions. This is about <em>authorization</em>, i.e. retrying such a request / operation without a change in permissions (or using another user account) is pointless.

Parameters

bool $condition

Exceptions

PermissionDeniedException

assertRegistered()

Ensure the given actor is authenticated.

This will throw an exception for guest users, signaling that <em>authorization</em> failed. Thus, they could retry the operation after logging in (or using other means of authentication).

Exceptions

NotAuthenticatedException

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

Parameters

string $ability
mixed $arguments

Exceptions

PermissionDeniedException

assertAdmin()

Exceptions

PermissionDeniedException

HasMany posts()

Define the relationship with the user's posts.

Return Value

HasMany

HasMany discussions()

Define the relationship with the user's discussions.

Return Value

HasMany

BelongsTo read()

Define the relationship with the user's read discussions.

Return Value

BelongsTo

BelongsToMany groups()

Define the relationship with the user's groups.

Return Value

BelongsToMany

visibleGroups()

HasMany notifications()

Define the relationship with the user's notifications.

Return Value

HasMany

HasMany emailTokens()

Define the relationship with the user's email tokens.

Return Value

HasMany

Builder permissions()

Define the relationship with the permissions of all of the groups that the user is in.

Return Value

Builder

string[] getPermissions()

Get a list of permissions that the user has.

Return Value

string[]

HasMany accessTokens()

Define the relationship with the user's access tokens.

Return Value

HasMany

loginProviders()

Get the user's login providers.

bool can(string $ability, array|mixed $arguments = [])

Parameters

string $ability
array|mixed $arguments

Return Value

bool

bool cannot(string $ability, array|mixed $arguments = [])

Parameters

string $ability
array|mixed $arguments

Return Value

bool

Session getSession()

Return Value

Session

setSession(Session $session)

Parameters

Session $session

static setHasher(Hasher $hasher)

Set the hasher with which to hash passwords.

Parameters

Hasher $hasher

static addPreference(string $key, callable $transformer = null, mixed $default = null)

Register a preference with a transformer and a default value.

Parameters

string $key
callable $transformer
mixed $default

static array addGroupProcessor(callable $callback)

Register a callback that processes a user's list of groups.

Parameters

callable $callback

Return Value

array $groupIds

static string getNotificationPreferenceKey(string $type, string $method)

Get the key for a preference which flags whether or not the user will receive a notification for $type via $method.

Parameters

string $type
string $method

Return Value

string

$this refreshCommentCount()

Refresh the user's comments count.

Return Value

$this

$this refreshDiscussionCount()

Refresh the user's comments count.

Return Value

$this

Group getGroupsAttribute()

Get the guest's group, containing only the 'guests' group model.

Return Value

Group