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