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 $customCasts from AbstractModel
static $defaults from AbstractModel
protected $tableAlias <p>An alias for the table name, used in queries.</p> from AbstractModel
protected $pendingEvents from EventGeneratorTrait
static protected $visibilityScopers from ScopeVisibilityTrait
protected $casts
protected string[]|null $permissions <p>An array of permissions that this user has.</p>
static protected callable[] $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 $displayNameDriver <p>A driver for getting display names.</p>
static protected $hasher <p>The hasher with which to hash passwords.</p>
static protected $gate <p>The access gate.</p>
static protected callable[] $passwordCheckers <p>Callbacks to check passwords.</p>
int $id
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
Group> $groups
Group> $visibleGroups
Notification> $notifications
AccessToken> $accessTokens
Post> $posts
Discussion> $discussions
Discussion> $read
Notification> $unreadNotifications
LoginProvider> $loginProviders
EmailToken> $emailTokens
PasswordToken> $passwordTokens

Methods

static 
boot()

No description

__construct(array $attributes = [])

No description

array
getCasts()

No description

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

array
releaseAfterSaveCallbacks()

No description

array
releaseAfterDeleteCallbacks()

No description

__call($method, $parameters)

No description

newModelQuery()

No description

qualifyColumn($column)

No description

mixed
withTableAlias(callable $callback)

No description

newCollection(array $models = [])

No description

__sleep()

No description

void
raise(object $event)

No description

array
releaseEvents()

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

static void
registerVisibilityScoper(callable $scoper, string|null $ability = null)

No description

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

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

static Builder
whereVisibleTo(User $user)

No description

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

No description

static void
setGate(Gate $gate)

No description

static void
setDisplayNameDriver(DriverInterface $driver)

No description

static void
setPasswordCheckers(array $checkers)

No description

rename(string $username)

No description

changeEmail(string $email)

No description

requestEmailChange(string $email)

No description

changePassword(string $password)

No description

void
setPasswordAttribute(string|null $value)

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

markAllAsRead()

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

markNotificationsAsRead()

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

changeAvatarPath(string|null $path)

No description

string|null
getAvatarUrlAttribute(string|null $value = null)

No description

string
getDisplayNameAttribute()

No description

bool
checkPassword(string $password)

No description

activate()

No description

bool
hasPermission(string $permission)

No description

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

No description

HasMany
unreadNotifications()

No description

Collection
getUnreadNotifications()

No description

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>

void
setPreferencesAttribute(array $value)

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

bool
shouldAlert(string $type)

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

bool
shouldEmail(string $type)

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

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

No description

setPreference(string $key, mixed $value)

No description

updateLastSeen()

No description

bool
isAdmin()

No description

bool
isGuest()

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

void
assertPermission(bool $condition)

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

void
assertRegistered()

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

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

No description

void
assertAdmin()

No description

HasMany
posts()

No description

HasMany
discussions()

No description

BelongsToMany
read()

No description

BelongsToMany
groups()

No description

BelongsToMany
visibleGroups()

No description

HasMany
notifications()

No description

HasMany
emailTokens()

No description

HasMany
passwordTokens()

No description

Builder
permissions()

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

array
getPermissions()

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

HasMany
accessTokens()

No description

HasMany
loginProviders()

No description

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

No description

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

No description

static void
setHasher(Hasher $hasher)

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

static void
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 the user will receive a notification for $type via $method.</p>

refreshCommentCount()

No description

refreshDiscussionCount()

No description

setNotificationPreference(string $type, string $method, bool $value)

<p>Set the value of a notification preference.</p>

Details

static boot()

__construct(array $attributes = [])

Parameters

array $attributes

array getCasts()

Return Value

array

getAttribute($key)

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

Parameters

$key

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

array releaseAfterSaveCallbacks()

Return Value

array

array releaseAfterDeleteCallbacks()

Return Value

array

__call($method, $parameters)

Parameters

$method
$parameters

newModelQuery()

qualifyColumn($column)

Parameters

$column

mixed withTableAlias(callable $callback)

Parameters

callable $callback

Return Value

mixed

Collection newCollection(array $models = [])

Parameters

array $models

Return Value

Collection

__sleep()

void raise(object $event)

Parameters

object $event

Return Value

void

array releaseEvents()

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

Return Value

array

static void registerVisibilityScoper(callable $scoper, string|null $ability = null)

Parameters

callable $scoper
string|null $ability

Return Value

void

Builder 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

Return Value

Builder

static Builder whereVisibleTo(User $user)

Parameters

User $user

Return Value

Builder

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

Parameters

string|null $username
string|null $email
string|null $password

Return Value

User

static void setGate(Gate $gate)

Parameters

Gate $gate

Return Value

void

static void setDisplayNameDriver(DriverInterface $driver)

Parameters

DriverInterface $driver

Return Value

void

static void setPasswordCheckers(array $checkers)

Parameters

array $checkers

Return Value

void

User rename(string $username)

Parameters

string $username

Return Value

User

User changeEmail(string $email)

Parameters

string $email

Return Value

User

User requestEmailChange(string $email)

Parameters

string $email

Return Value

User

User changePassword(string $password)

Parameters

string $password

Return Value

User

void setPasswordAttribute(string|null $value)

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

Parameters

string|null $value

Return Value

void

User markAllAsRead()

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

Return Value

User

User markNotificationsAsRead()

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

Return Value

User

User changeAvatarPath(string|null $path)

Parameters

string|null $path

Return Value

User

string|null getAvatarUrlAttribute(string|null $value = null)

Parameters

string|null $value

Return Value

string|null

string getDisplayNameAttribute()

Return Value

string

bool checkPassword(string $password)

Parameters

string $password

Return Value

bool

User activate()

Return Value

User

bool hasPermission(string $permission)

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

Return Value

int

protected HasMany unreadNotifications()

Return Value

HasMany

protected Collection getUnreadNotifications()

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

void setPreferencesAttribute(array $value)

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

Parameters

array $value

Return Value

void

bool shouldAlert(string $type)

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

Parameters

string $type

Return Value

bool

bool shouldEmail(string $type)

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

Parameters

string $type

Return Value

bool

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

Parameters

string $key
mixed $default

Return Value

mixed

User setPreference(string $key, mixed $value)

Parameters

string $key
mixed $value

Return Value

User

User updateLastSeen()

Return Value

User

bool isAdmin()

Return Value

bool

bool isGuest()

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

Return Value

bool

void 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

Return Value

void

Exceptions

PermissionDeniedException

void 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>

Return Value

void

Exceptions

NotAuthenticatedException

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

Parameters

string $ability
mixed $arguments

Return Value

void

Exceptions

PermissionDeniedException

void assertAdmin()

Return Value

void

Exceptions

PermissionDeniedException

HasMany posts()

Return Value

HasMany

HasMany discussions()

Return Value

HasMany

BelongsToMany read()

Return Value

BelongsToMany

BelongsToMany groups()

Return Value

BelongsToMany

BelongsToMany visibleGroups()

Return Value

BelongsToMany

HasMany notifications()

Return Value

HasMany

HasMany emailTokens()

Return Value

HasMany

HasMany passwordTokens()

Return Value

HasMany

Builder permissions()

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

Return Value

Builder

array getPermissions()

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

Return Value

array

HasMany accessTokens()

Return Value

HasMany

HasMany loginProviders()

Return Value

HasMany

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

Parameters

string $ability
mixed $arguments

Return Value

bool

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

Parameters

string $ability
mixed $arguments

Return Value

bool

static void setHasher(Hasher $hasher)

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

Parameters

Hasher $hasher

Return Value

void

static void 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

Return Value

void

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 the user will receive a notification for $type via $method.</p>

Parameters

string $type
string $method

Return Value

string

User refreshCommentCount()

Return Value

User

User refreshDiscussionCount()

Return Value

User

User setNotificationPreference(string $type, string $method, bool $value)

<p>Set the value of a notification preference.</p>

Parameters

string $type
string $method
bool $value

Return Value

User