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 | ||
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> | ||
int | $id | |||
string | $username | |||
string | $display_name | |||
string | ||||
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
<p>Get an attribute from the model. If nothing is found, attempt to load a custom relation method with this key.</p>
<p>Register a callback to be run once after the model is saved.</p>
<p>Register a callback to be run once after the model is deleted.</p>
<p>Scope a query to only include records that are visible to a user.</p>
<p>Check whether the user has a certain permission based on their groups.</p>
<p>Check whether the user has a permission that is like the given string, based on their groups.</p>
<p>Get the notification types that should be alerted to this user, according to their preferences.</p>
<p>Return query builder for all notifications that have not been read yet.</p>
<p>Get the values of all registered preferences for this user, by transforming their stored preferences and merging them with the defaults.</p>
<p>Encode an array of preferences for storage in the database.</p>
<p>Check whether or not the user should receive an alert for a notification type.</p>
<p>Check whether or not the user should receive an email for a notification type.</p>
<p>Get the value of a preference for this user.</p>
<p>Define the relationship with the permissions of all of the groups that the user is in.</p>
<p>Register a preference with a transformer and a default value.</p>
<p>Register a callback that processes a user's list of groups.</p>
<p>Get the key for a preference which flags whether or not the user will receive a notification for $type via $method.</p>
Details
at
line 134
static
boot()
<p>Boot the model.</p>
in AbstractModel
at
line 85
__construct(array $attributes = [])
<p>{@inheritdoc}</p>
in AbstractModel
at
line 105
array
getDates()
<p>Get the attributes that should be converted to dates.</p>
in AbstractModel
at
line 123
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>
in AbstractModel
at
line 149
protected mixed
getCustomRelation(string $name)
<p>Get a custom relation object.</p>
in AbstractModel
at
line 165
void
afterSave(callable $callback)
<p>Register a callback to be run once after the model is saved.</p>
in AbstractModel
at
line 176
void
afterDelete(callable $callback)
<p>Register a callback to be run once after the model is deleted.</p>
in AbstractModel
at
line 184
callable[]
releaseAfterSaveCallbacks()
in AbstractModel
at
line 196
callable[]
releaseAfterDeleteCallbacks()
in AbstractModel
at
line 208
__call($method, $arguments)
<p>{@inheritdoc}</p>
in EventGeneratorTrait
at
line 24
raise(mixed $event)
<p>Raise a new event.</p>
in EventGeneratorTrait
at
line 34
array
releaseEvents()
<p>Return and reset all pending events.</p>
in ScopeVisibilityTrait
at
line 20
static
registerVisibilityScoper($scoper, $ability = null)
in ScopeVisibilityTrait
at
line 41
scopeWhereVisibleTo(Builder $query, User $actor, string $ability = 'view')
<p>Scope a query to only include records that are visible to a user.</p>
at
line 160
static User
register(string $username, string $email, string $password)
<p>Register a new user.</p>
at
line 177
static
setGate(Gate $gate)
at
line 187
static
setDisplayNameDriver(DriverInterface $driver)
<p>Set the display name driver.</p>
at
line 192
static
setPasswordCheckers(array $checkers)
at
line 203
$this
rename(string $username)
<p>Rename the user.</p>
at
line 221
$this
changeEmail(string $email)
<p>Change the user's email.</p>
at
line 238
$this
requestEmailChange(string $email)
<p>Request that the user's email be changed.</p>
at
line 253
$this
changePassword(string $password)
<p>Change the user's password.</p>
at
line 267
setPasswordAttribute(string $value)
<p>Set the password attribute, storing it as a hash.</p>
at
line 277
$this
markAllAsRead()
<p>Mark all discussions as read.</p>
at
line 289
$this
markNotificationsAsRead()
<p>Mark all notifications as read.</p>
at
line 302
$this
changeAvatarPath(string $path)
<p>Change the path of the user avatar.</p>
at
line 318
string
getAvatarUrlAttribute(string $value = null)
<p>Get the URL of the user's avatar.</p>
at
line 332
string
getDisplayNameAttribute()
<p>Get the user's display name.</p>
at
line 343
bool
checkPassword(string $password)
<p>Check if a given password matches the user's password.</p>
at
line 365
$this
activate()
<p>Activate the user's account.</p>
at
line 382
bool
hasPermission(string $permission)
<p>Check whether the user has a certain permission based on their groups.</p>
at
line 398
bool
hasPermissionLike(string $match)
<p>Check whether the user has a permission that is like the given string, based on their groups.</p>
at
line 428
array
getAlertableNotificationTypes()
<p>Get the notification types that should be alerted to this user, according to their preferences.</p>
at
line 440
int
getUnreadNotificationCount()
<p>Get the number of unread notifications for the user.</p>
at
line 450
protected HasMany
unreadNotifications()
<p>Return query builder for all notifications that have not been read yet.</p>
at
line 464
protected Collection
getUnreadNotifications()
<p>Get all notifications that have not been read yet.</p>
at
line 474
int
getNewNotificationCount()
<p>Get the number of new, unseen notifications for the user.</p>
at
line 488
array
getPreferencesAttribute(string $value)
<p>Get the values of all registered preferences for this user, by transforming their stored preferences and merging them with the defaults.</p>
at
line 504
setPreferencesAttribute(mixed $value)
<p>Encode an array of preferences for storage in the database.</p>
at
line 516
bool
shouldAlert(string $type)
<p>Check whether or not the user should receive an alert for a notification type.</p>
at
line 528
bool
shouldEmail(string $type)
<p>Check whether or not the user should receive an email for a notification type.</p>
at
line 540
mixed
getPreference(string $key, mixed $default = null)
<p>Get the value of a preference for this user.</p>
at
line 552
$this
setPreference(string $key, mixed $value)
<p>Set the value of a preference for this user.</p>
at
line 574
$this
updateLastSeen()
<p>Set the user as being last seen just now.</p>
at
line 590
bool
isAdmin()
<p>Check whether or not the user is an administrator.</p>
at
line 600
bool
isGuest()
<p>Check whether or not the user is a guest.</p>
at
line 616
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>
at
line 632
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>
at
line 644
assertCan(string $ability, mixed $arguments = null)
at
line 654
assertAdmin()
at
line 664
HasMany
posts()
<p>Define the relationship with the user's posts.</p>
at
line 674
HasMany
discussions()
<p>Define the relationship with the user's discussions.</p>
at
line 684
BelongsTo
read()
<p>Define the relationship with the user's read discussions.</p>
at
line 694
BelongsToMany
groups()
<p>Define the relationship with the user's groups.</p>
at
line 699
visibleGroups()
at
line 709
HasMany
notifications()
<p>Define the relationship with the user's notifications.</p>
at
line 719
HasMany
emailTokens()
<p>Define the relationship with the user's email tokens.</p>
at
line 729
HasMany
passwordTokens()
<p>Define the relationship with the user's email tokens.</p>
at
line 740
Builder
permissions()
<p>Define the relationship with the permissions of all of the groups that the user is in.</p>
at
line 764
string[]
getPermissions()
<p>Get a list of permissions that the user has.</p>
at
line 778
HasMany
accessTokens()
<p>Define the relationship with the user's access tokens.</p>
at
line 786
loginProviders()
<p>Get the user's login providers.</p>
at
line 796
bool
can(string $ability, array|mixed $arguments = null)
at
line 806
bool
cannot(string $ability, array|mixed $arguments = null)
at
line 818
static
setHasher(Hasher $hasher)
<p>Set the hasher with which to hash passwords.</p>
at
line 832
static
registerPreference(string $key, callable $transformer = null, mixed $default = null)
<p>Register a preference with a transformer and a default value.</p>
at
line 845
static array
addGroupProcessor(callable $callback)
<p>Register a callback that processes a user's list of groups.</p>
at
line 858
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>
at
line 868
$this
refreshCommentCount()
<p>Refresh the user's comments count.</p>
at
line 883
$this
refreshDiscussionCount()
<p>Refresh the user's comments count.</p>