class User extends AbstractModel

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
protected array $pendingEvents from EventGeneratorTrait
protected $table {@inheritdoc}
protected $dates {@inheritdoc}
protected string[]|null $permissions An array of permissions that this user has.
protected SessionInterface $session
array $preferences
static protected Hasher $hasher The hasher with which to hash passwords.
static protected Gate $gate The access gate.
int $id
string $username
string $email
bool $is_activated
string $password
string $locale
string $bio
string|null $avatar_path
string $avatar_url
Carbon|null $join_time
Carbon|null $last_seen_time
Carbon|null $read_time
Carbon|null $notifications_read_time
int $discussions_count
int $comments_count

Methods

static 
boot()

Boot the model.

__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.

static Gate
getGate()

No description

static 
setGate(Gate $gate)

No description

$this
rename(string $username)

Rename the user.

$this
changeEmail(string $email)

Change the user's email.

$this
requestEmailChange(string $email)

Request that the user's email be changed.

$this
changePassword(string $password)

Change the user's password.

setPasswordAttribute(string $value)

Set the password attribute, storing it as a hash.

$this
changeBio(string $bio)

Change the user's bio.

$this
markAllAsRead()

Mark all discussions as read.

$this
markNotificationsAsRead()

Mark all notifications as read.

$this
changeAvatarPath(string $path)

Change the path of the user avatar.

string
getAvatarUrlAttribute()

Get the URL of the user's avatar.

string
getLocaleAttribute(string $value)

Get the user's locale, falling back to the forum's default if they haven't set one.

bool
checkPassword(string $password)

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

$this
activate()

Activate the user's account.

bool
hasPermission(string $permission)

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

bool
hasPermissionLike(string $match)

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

array
getAlertableNotificationTypes()

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

int
getUnreadNotificationsCount()

Get the number of unread notifications for the user.

Collection
getUnreadNotifications()

Get all notifications that have not been read yet.

int
getNewNotificationsCount()

Get the number of new, unseen notifications for the 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.

setPreferencesAttribute(mixed $value)

Encode an array of preferences for storage in the database.

bool
shouldAlert(string $type)

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

bool
shouldEmail(string $type)

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

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

Get the value of a preference for this user.

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

Set the value of a preference for this user.

$this
updateLastSeen()

Set the user as being last seen just now.

bool
isAdmin()

Check whether or not the user is an administrator.

bool
isGuest()

Check whether or not the user is a guest.

HasMany
posts()

Define the relationship with the user's posts.

BelongsTo
read()

Define the relationship with the user's read discussions.

BelongsToMany
groups()

Define the relationship with the user's groups.

HasMany
notifications()

Define the relationship with the user's notifications.

Builder
permissions()

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

string[]
getPermissions()

Get a list of permissions that the user has.

HasMany
accessTokens()

Define the relationship with the user's access tokens.

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

No description

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

No description

SessionInterface
getSession()

No description

setSession(SessionInterface $session)

No description

static 
setHasher(Hasher $hasher)

Set the hasher with which to hash passwords.

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

Register a preference with a transformer and a default value.

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.

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 Gate getGate()

Return Value

Gate

static setGate(Gate $gate)

Parameters

Gate $gate

$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 changeBio(string $bio)

Change the user's bio.

Parameters

string $bio

Return Value

$this

$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()

Get the URL of the user's avatar.

Return Value

string

string getLocaleAttribute(string $value)

Get the user's locale, falling back to the forum's default if they haven't set one.

Parameters

string $value

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 getUnreadNotificationsCount()

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 getNewNotificationsCount()

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

HasMany posts()

Define the relationship with the user's posts.

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

HasMany notifications()

Define the relationship with the user's notifications.

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

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

SessionInterface getSession()

Return Value

SessionInterface

setSession(SessionInterface $session)

Parameters

SessionInterface $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 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