class User extends AbstractModel
Traits
Constants
| LAST_SEEN_UPDATE_DIFF |
Difference from the current `last_seen` 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 | $customCasts | from AbstractModel |
|
|
| static | $defaults | from AbstractModel |
|
|
| protected string|null | $tableAlias | An alias for the table name, used in queries. | from AbstractModel |
|
| int | $id |
|
||
| protected array | $pendingEvents | from EventGeneratorTrait |
|
|
| static protected | $visibilityScopers | from ScopeVisibilityTrait |
|
|
| protected array | $dates | The attributes that should be mutated to dates. |
|
|
| protected string[]|null | $permissions | An array of permissions that this user has. |
|
|
| static protected | $groupProcessors | An array of callables, through each of which the user's list of groups is passed before being returned. |
|
|
| array | $preferences |
|
||
| static protected DriverInterface | $displayNameDriver | A driver for getting display names. |
|
|
| static protected Hasher | $hasher | The hasher with which to hash passwords. |
|
|
| static protected Gate | $gate | The access gate. |
|
|
| static protected array | $passwordCheckers | Callbacks to check passwords. |
|
|
| 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
Get an attribute from the model. If nothing is found, attempt to load a custom relation method with this key.
Register a callback to be run once after the model is saved.
Register a callback to be run once after the model is deleted.
Scope a query to only include records that are visible to a user.
Check whether the user has a certain permission based on their groups.
Check whether the user has a permission that is like the given string, based on their groups.
Get the notification types that should be alerted to this user, according to their preferences.
Return query builder for all notifications that have not been read yet.
Get the values of all registered preferences for this user, by transforming their stored preferences and merging them with the defaults.
Check whether or not the user should receive an alert for a notification type.
Check whether or not the user should receive an email for a notification type.
Get the value of a preference for this user.
Define the relationship with the permissions of all of the groups that the user is in.
Register a preference with a transformer and a default value.
Register a callback that processes a user's list of groups.
Get the key for a preference which flags whether or not the user will receive a notification for $type via $method.
Details
at
line 136
static
boot()
Boot the model.
in AbstractModel
at
line 97
__construct(array $attributes = [])
{@inheritdoc}
in AbstractModel
at
line 115
getCasts()
{@inheritdoc}
in AbstractModel
at
line 133
mixed
getAttribute(string $key)
Get an attribute from the model. If nothing is found, attempt to load a custom relation method with this key.
in AbstractModel
at
line 159
protected mixed
getCustomRelation(string $name)
Get a custom relation object.
in AbstractModel
at
line 175
void
afterSave(callable $callback)
Register a callback to be run once after the model is saved.
in AbstractModel
at
line 186
void
afterDelete(callable $callback)
Register a callback to be run once after the model is deleted.
in AbstractModel
at
line 194
callable[]
releaseAfterSaveCallbacks()
in AbstractModel
at
line 206
callable[]
releaseAfterDeleteCallbacks()
in AbstractModel
at
line 218
__call($method, $arguments)
{@inheritdoc}
in AbstractModel
at
line 227
newModelQuery()
in AbstractModel
at
line 238
qualifyColumn($column)
in AbstractModel
at
line 247
withTableAlias(callable $callback)
in AbstractModel
at
line 262
newCollection(Collection|array $models = [])
in EventGeneratorTrait
at
line 24
raise(mixed $event)
Raise a new event.
in EventGeneratorTrait
at
line 34
array
releaseEvents()
Return and reset all pending events.
in ScopeVisibilityTrait
at
line 20
static
registerVisibilityScoper($scoper, $ability = null)
in ScopeVisibilityTrait
at
line 41
scopeWhereVisibleTo(Builder $query, User $actor, string $ability = 'view')
Scope a query to only include records that are visible to a user.
at
line 162
static User
register(string $username, string $email, string $password)
Register a new user.
at
line 189
static
setDisplayNameDriver(DriverInterface $driver)
Set the display name driver.
at
line 194
static
setPasswordCheckers(array $checkers)
at
line 205
$this
rename(string $username)
Rename the user.
at
line 223
$this
changeEmail(string $email)
Change the user's email.
at
line 240
$this
requestEmailChange(string $email)
Request that the user's email be changed.
at
line 255
$this
changePassword(string $password)
Change the user's password.
at
line 269
setPasswordAttribute(string $value)
Set the password attribute, storing it as a hash.
at
line 279
$this
markAllAsRead()
Mark all discussions as read.
at
line 291
$this
markNotificationsAsRead()
Mark all notifications as read.
at
line 304
$this
changeAvatarPath(string|null $path)
Change the path of the user avatar.
at
line 319
string
getAvatarUrlAttribute(string $value = null)
Get the URL of the user's avatar.
at
line 333
string
getDisplayNameAttribute()
Get the user's display name.
at
line 344
bool
checkPassword(string $password)
Check if a given password matches the user's password.
at
line 366
$this
activate()
Activate the user's account.
at
line 383
bool
hasPermission(string $permission)
Check whether the user has a certain permission based on their groups.
at
line 399
bool
hasPermissionLike(string $match)
Check whether the user has a permission that is like the given string, based on their groups.
at
line 420
array
getAlertableNotificationTypes()
Get the notification types that should be alerted to this user, according to their preferences.
at
line 432
int
getUnreadNotificationCount()
Get the number of unread notifications for the user.
at
line 449
protected HasMany
unreadNotifications()
Return query builder for all notifications that have not been read yet.
at
line 463
protected Collection
getUnreadNotifications()
Get all notifications that have not been read yet.
at
line 473
int
getNewNotificationCount()
Get the number of new, unseen notifications for the user.
at
line 493
array
getPreferencesAttribute(string|null $value)
Get the values of all registered preferences for this user, by transforming their stored preferences and merging them with the defaults.
at
line 509
setPreferencesAttribute(mixed $value)
Encode an array of preferences for storage in the database.
at
line 521
bool
shouldAlert(string $type)
Check whether or not the user should receive an alert for a notification type.
at
line 533
bool
shouldEmail(string $type)
Check whether or not the user should receive an email for a notification type.
at
line 545
mixed
getPreference(string $key, mixed $default = null)
Get the value of a preference for this user.
at
line 557
$this
setPreference(string $key, mixed $value)
Set the value of a preference for this user.
at
line 579
$this
updateLastSeen()
Set the user as being last seen just now.
at
line 595
bool
isAdmin()
Check whether or not the user is an administrator.
at
line 605
bool
isGuest()
Check whether or not the user is a guest.
at
line 621
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 *authorization*, i.e. retrying such a request / operation without a change in permissions (or using another user account) is pointless.
at
line 637
assertRegistered()
Ensure the given actor is authenticated.
This will throw an exception for guest users, signaling that *authorization* failed. Thus, they could retry the operation after logging in (or using other means of authentication).
at
line 649
assertCan(string $ability, mixed $arguments = null)
at
line 659
assertAdmin()
at
line 669
HasMany
posts()
Define the relationship with the user's posts.
at
line 679
HasMany
discussions()
Define the relationship with the user's discussions.
at
line 689
Discussion>
read()
Define the relationship with the user's read discussions.
at
line 699
BelongsToMany
groups()
Define the relationship with the user's groups.
at
line 704
visibleGroups()
at
line 714
HasMany
notifications()
Define the relationship with the user's notifications.
at
line 724
HasMany
emailTokens()
Define the relationship with the user's email tokens.
at
line 734
HasMany
passwordTokens()
Define the relationship with the user's email tokens.
at
line 745
Builder
permissions()
Define the relationship with the permissions of all of the groups that the user is in.
at
line 769
string[]
getPermissions()
Get a list of permissions that the user has.
at
line 783
HasMany
accessTokens()
Define the relationship with the user's access tokens.
at
line 791
loginProviders()
Get the user's login providers.
at
line 801
bool
can(string $ability, array|mixed $arguments = null)
at
line 811
bool
cannot(string $ability, array|mixed $arguments = null)
at
line 823
static
setHasher(Hasher $hasher)
Set the hasher with which to hash passwords.
at
line 837
static
registerPreference(string $key, callable $transformer = null, mixed $default = null)
Register a preference with a transformer and a default value.
at
line 850
static void
addGroupProcessor(callable $callback)
Register a callback that processes a user's list of groups.
at
line 863
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.
at
line 873
$this
refreshCommentCount()
Refresh the user's comments count.
at
line 888
$this
refreshDiscussionCount()
Refresh the user's comments count.