class User extends AbstractModel

Traits

Constants

LAST_SEEN_UPDATE_DIFF

<p>Difference from the current <code>last_seen</code> attribute value before <code>updateLastSeen()</code> will update the attribute on the DB. Measured in seconds.</p>

Properties

bool $timestamps <p>Indicates if the model should be timestamped. Turn off by default.</p> from AbstractModel
protected callable[] $afterSaveCallbacks <p>An array of callbacks to be run once after the model is saved.</p> from AbstractModel
protected callable[] $afterDeleteCallbacks <p>An array of callbacks to be run once after the model is deleted.</p> from AbstractModel
static $customRelations from AbstractModel
static $dateAttributes from AbstractModel
static $defaults from AbstractModel
int $id
protected array $pendingEvents from EventGeneratorTrait
static protected $visibilityScopers from ScopeVisibilityTrait
protected array $dates <p>The attributes that should be mutated to dates.</p>
protected string[]|null $permissions <p>An array of permissions that this user has.</p>
static protected $groupProcessors <p>An array of callables, through each of which the user's list of groups is passed before being returned.</p>
array $preferences
static protected DriverInterface $displayNameDriver <p>A driver for getting display names.</p>
static protected Hasher $hasher <p>The hasher with which to hash passwords.</p>
static protected Gate $gate <p>The access gate.</p>
static protected array $passwordCheckers <p>Callbacks to check passwords.</p>
string $username
string $display_name
string $email
bool $is_email_confirmed
string $password
string|null $avatar_url
Carbon|null $joined_at
Carbon|null $last_seen_at
Carbon|null $marked_all_as_read_at
Carbon|null $read_notifications_at
int $discussion_count
int $comment_count

Methods

static 
boot()

<p>Boot the model.</p>

__construct(array $attributes = [])

<p>{@inheritdoc}</p>

array
getDates()

<p>Get the attributes that should be converted to dates.</p>

mixed
getAttribute(string $key)

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

mixed
getCustomRelation(string $name)

<p>Get a custom relation object.</p>

void
afterSave(callable $callback)

<p>Register a callback to be run once after the model is saved.</p>

void
afterDelete(callable $callback)

<p>Register a callback to be run once after the model is deleted.</p>

callable[]
releaseAfterSaveCallbacks()

No description

callable[]
releaseAfterDeleteCallbacks()

No description

__call($method, $arguments)

<p>{@inheritdoc}</p>

raise(mixed $event)

<p>Raise a new event.</p>

array
releaseEvents()

<p>Return and reset all pending events.</p>

static 
registerVisibilityScoper($scoper, $ability = null)

No description

scopeWhereVisibleTo(Builder $query, User $actor, string $ability = 'view')

<p>Scope a query to only include records that are visible to a user.</p>

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

<p>Register a new user.</p>

static 
setGate(Gate $gate)

No description

static 
setDisplayNameDriver(DriverInterface $driver)

<p>Set the display name driver.</p>

static 
setPasswordCheckers(array $checkers)

No description

$this
rename(string $username)

<p>Rename the user.</p>

$this
changeEmail(string $email)

<p>Change the user's email.</p>

$this
requestEmailChange(string $email)

<p>Request that the user's email be changed.</p>

$this
changePassword(string $password)

<p>Change the user's password.</p>

setPasswordAttribute(string $value)

<p>Set the password attribute, storing it as a hash.</p>

$this
markAllAsRead()

<p>Mark all discussions as read.</p>

$this
markNotificationsAsRead()

<p>Mark all notifications as read.</p>

$this
changeAvatarPath(string|null $path)

<p>Change the path of the user avatar.</p>

string
getAvatarUrlAttribute(string $value = null)

<p>Get the URL of the user's avatar.</p>

string
getDisplayNameAttribute()

<p>Get the user's display name.</p>

bool
checkPassword(string $password)

<p>Check if a given password matches the user's password.</p>

$this
activate()

<p>Activate the user's account.</p>

bool
hasPermission(string $permission)

<p>Check whether the user has a certain permission based on their groups.</p>

bool
hasPermissionLike(string $match)

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

array
getAlertableNotificationTypes()

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

int
getUnreadNotificationCount()

<p>Get the number of unread notifications for the user.</p>

HasMany
unreadNotifications()

<p>Return query builder for all notifications that have not been read yet.</p>

Collection
getUnreadNotifications()

<p>Get all notifications that have not been read yet.</p>

int
getNewNotificationCount()

<p>Get the number of new, unseen notifications for the user.</p>

array
getPreferencesAttribute(string|null $value)

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

setPreferencesAttribute(mixed $value)

<p>Encode an array of preferences for storage in the database.</p>

bool
shouldAlert(string $type)

<p>Check whether or not the user should receive an alert for a notification type.</p>

bool
shouldEmail(string $type)

<p>Check whether or not the user should receive an email for a notification type.</p>

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

<p>Get the value of a preference for this user.</p>

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

<p>Set the value of a preference for this user.</p>

$this
updateLastSeen()

<p>Set the user as being last seen just now.</p>

bool
isAdmin()

<p>Check whether or not the user is an administrator.</p>

bool
isGuest()

<p>Check whether or not the user is a guest.</p>

assertPermission(bool $condition)

<p>Ensure the current user is allowed to do something.</p>

assertRegistered()

<p>Ensure the given actor is authenticated.</p>

assertCan(string $ability, mixed $arguments = null)

No description

assertAdmin()

No description

HasMany
posts()

<p>Define the relationship with the user's posts.</p>

HasMany
discussions()

<p>Define the relationship with the user's discussions.</p>

Discussion>
read()

<p>Define the relationship with the user's read discussions.</p>

BelongsToMany
groups()

<p>Define the relationship with the user's groups.</p>

visibleGroups()

No description

HasMany
notifications()

<p>Define the relationship with the user's notifications.</p>

HasMany
emailTokens()

<p>Define the relationship with the user's email tokens.</p>

HasMany
passwordTokens()

<p>Define the relationship with the user's email tokens.</p>

Builder
permissions()

<p>Define the relationship with the permissions of all of the groups that the user is in.</p>

string[]
getPermissions()

<p>Get a list of permissions that the user has.</p>

HasMany
accessTokens()

<p>Define the relationship with the user's access tokens.</p>

loginProviders()

<p>Get the user's login providers.</p>

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

No description

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

No description

static 
setHasher(Hasher $hasher)

<p>Set the hasher with which to hash passwords.</p>

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

<p>Register a preference with a transformer and a default value.</p>

static void
addGroupProcessor(callable $callback)

<p>Register a callback that processes a user's list of groups.</p>

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

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

$this
refreshCommentCount()

<p>Refresh the user's comments count.</p>

$this
refreshDiscussionCount()

<p>Refresh the user's comments count.</p>

Details

static boot()

<p>Boot the model.</p>

__construct(array $attributes = [])

<p>{@inheritdoc}</p>

Parameters

array $attributes

array getDates()

<p>Get the attributes that should be converted to dates.</p>

Return Value

array

mixed getAttribute(string $key)

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

Parameters

string $key

Return Value

mixed

protected mixed getCustomRelation(string $name)

<p>Get a custom relation object.</p>

Parameters

string $name

Return Value

mixed

void afterSave(callable $callback)

<p>Register a callback to be run once after the model is saved.</p>

Parameters

callable $callback

Return Value

void

void afterDelete(callable $callback)

<p>Register a callback to be run once after the model is deleted.</p>

Parameters

callable $callback

Return Value

void

callable[] releaseAfterSaveCallbacks()

Return Value

callable[]

callable[] releaseAfterDeleteCallbacks()

Return Value

callable[]

__call($method, $arguments)

<p>{@inheritdoc}</p>

Parameters

$method
$arguments

raise(mixed $event)

<p>Raise a new event.</p>

Parameters

mixed $event

array releaseEvents()

<p>Return and reset all pending events.</p>

Return Value

array

static registerVisibilityScoper($scoper, $ability = null)

Parameters

$scoper
$ability

scopeWhereVisibleTo(Builder $query, User $actor, string $ability = 'view')

<p>Scope a query to only include records that are visible to a user.</p>

Parameters

Builder $query
User $actor
string $ability

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

<p>Register a new user.</p>

Parameters

string $username
string $email
string $password

Return Value

User

static setGate(Gate $gate)

Parameters

Gate $gate

static setDisplayNameDriver(DriverInterface $driver)

<p>Set the display name driver.</p>

Parameters

DriverInterface $driver

static setPasswordCheckers(array $checkers)

Parameters

array $checkers

$this rename(string $username)

<p>Rename the user.</p>

Parameters

string $username

Return Value

$this

$this changeEmail(string $email)

<p>Change the user's email.</p>

Parameters

string $email

Return Value

$this

$this requestEmailChange(string $email)

<p>Request that the user's email be changed.</p>

Parameters

string $email

Return Value

$this

$this changePassword(string $password)

<p>Change the user's password.</p>

Parameters

string $password

Return Value

$this

setPasswordAttribute(string $value)

<p>Set the password attribute, storing it as a hash.</p>

Parameters

string $value

$this markAllAsRead()

<p>Mark all discussions as read.</p>

Return Value

$this

$this markNotificationsAsRead()

<p>Mark all notifications as read.</p>

Return Value

$this

$this changeAvatarPath(string|null $path)

<p>Change the path of the user avatar.</p>

Parameters

string|null $path

Return Value

$this

string getAvatarUrlAttribute(string $value = null)

<p>Get the URL of the user's avatar.</p>

Parameters

string $value

Return Value

string

string getDisplayNameAttribute()

<p>Get the user's display name.</p>

Return Value

string

bool checkPassword(string $password)

<p>Check if a given password matches the user's password.</p>

Parameters

string $password

Return Value

bool

$this activate()

<p>Activate the user's account.</p>

Return Value

$this

bool hasPermission(string $permission)

<p>Check whether the user has a certain permission based on their groups.</p>

Parameters

string $permission

Return Value

bool

bool hasPermissionLike(string $match)

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

Parameters

string $match

Return Value

bool

array getAlertableNotificationTypes()

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

Return Value

array

int getUnreadNotificationCount()

<p>Get the number of unread notifications for the user.</p>

Return Value

int

protected HasMany unreadNotifications()

<p>Return query builder for all notifications that have not been read yet.</p>

Return Value

HasMany

protected Collection getUnreadNotifications()

<p>Get all notifications that have not been read yet.</p>

Return Value

Collection

int getNewNotificationCount()

<p>Get the number of new, unseen notifications for the user.</p>

Return Value

int

array getPreferencesAttribute(string|null $value)

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

Parameters

string|null $value

Return Value

array

setPreferencesAttribute(mixed $value)

<p>Encode an array of preferences for storage in the database.</p>

Parameters

mixed $value

bool shouldAlert(string $type)

<p>Check whether or not the user should receive an alert for a notification type.</p>

Parameters

string $type

Return Value

bool

bool shouldEmail(string $type)

<p>Check whether or not the user should receive an email for a notification type.</p>

Parameters

string $type

Return Value

bool

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

<p>Get the value of a preference for this user.</p>

Parameters

string $key
mixed $default

Return Value

mixed

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

<p>Set the value of a preference for this user.</p>

Parameters

string $key
mixed $value

Return Value

$this

$this updateLastSeen()

<p>Set the user as being last seen just now.</p>

Return Value

$this

bool isAdmin()

<p>Check whether or not the user is an administrator.</p>

Return Value

bool

bool isGuest()

<p>Check whether or not the user is a guest.</p>

Return Value

bool

assertPermission(bool $condition)

<p>Ensure the current user is allowed to do something.</p>

<p>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.</p>

Parameters

bool $condition

Exceptions

PermissionDeniedException

assertRegistered()

<p>Ensure the given actor is authenticated.</p>

<p>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).</p>

assertCan(string $ability, mixed $arguments = null)

Parameters

string $ability
mixed $arguments

Exceptions

PermissionDeniedException

assertAdmin()

HasMany posts()

<p>Define the relationship with the user's posts.</p>

Return Value

HasMany

HasMany discussions()

<p>Define the relationship with the user's discussions.</p>

Return Value

HasMany

Discussion> read()

<p>Define the relationship with the user's read discussions.</p>

Return Value

Discussion>

BelongsToMany groups()

<p>Define the relationship with the user's groups.</p>

Return Value

BelongsToMany

visibleGroups()

HasMany notifications()

<p>Define the relationship with the user's notifications.</p>

Return Value

HasMany

HasMany emailTokens()

<p>Define the relationship with the user's email tokens.</p>

Return Value

HasMany

HasMany passwordTokens()

<p>Define the relationship with the user's email tokens.</p>

Return Value

HasMany

Builder permissions()

<p>Define the relationship with the permissions of all of the groups that the user is in.</p>

Return Value

Builder

string[] getPermissions()

<p>Get a list of permissions that the user has.</p>

Return Value

string[]

HasMany accessTokens()

<p>Define the relationship with the user's access tokens.</p>

Return Value

HasMany

loginProviders()

<p>Get the user's login providers.</p>

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

Parameters

string $ability
array|mixed $arguments

Return Value

bool

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

Parameters

string $ability
array|mixed $arguments

Return Value

bool

static setHasher(Hasher $hasher)

<p>Set the hasher with which to hash passwords.</p>

Parameters

Hasher $hasher

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

<p>Register a preference with a transformer and a default value.</p>

Parameters

string $key
callable $transformer
mixed $default

static void addGroupProcessor(callable $callback)

<p>Register a callback that processes a user's list of groups.</p>

Parameters

callable $callback

Return Value

void

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

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

Parameters

string $type
string $method

Return Value

string

$this refreshCommentCount()

<p>Refresh the user's comments count.</p>

Return Value

$this

$this refreshDiscussionCount()

<p>Refresh the user's comments count.</p>

Return Value

$this