User extends Model implements UserInterface Uses SoftDeletes
User Class.
Represents a User object as stored in the database.
Tags
Table of Contents
$table | The name of the table for the current model. | string |
---|---|---|
$fillable | Fields that should be mass-assignable when creating a new User. | string[] |
$hidden | A list of attributes to hide by default when using toArray() and toJson(). | string[] |
$dates | The attributes that should be mutated to dates. | string[] |
$appends | ||
$dispatchesEvents | Events used to handle the user object cache on update and deletion. | array |
$cachedPermissions | Cached dictionary of permissions for the user. | array |
$timestamps | Enable timestamps for Users. | bool |
$id | int | |
$user_name | string | |
$first_name | string | |
$last_name | string | |
string | ||
$locale | string | |
$theme | string | |
$group_id | int | |
$flag_verified | bool | |
$flag_enabled | bool | |
$last_activity_id | int | |
$created_at | timestamp | |
$updated_at | timestamp | |
$password | string | |
$deleted_at | timestamp | |
$ci | ContainerInterface | |
$timestamps | bool | |
$manyMethodsExtended | The many to many relationship methods. | array |
__isset() | Determine if the property for this object exists. | bool |
__get() | Get a property for this object. | string |
activities() | Get all activities for this user. | HasMany |
delete() | Delete this user from the database, along with any linked roles and activities. | bool |
exists() | Determines whether a user exists, including checking soft-deleted records. | User|null |
getCache() | Return a cache instance specific to that user. | Store |
getFullNameAttribute() | Allows you to get the full name of the user using `$user->full_name`. | string |
getCachedPermissions() | Retrieve the cached permissions dictionary for this user. | array |
reloadCachedPermissions() | Retrieve the cached permissions dictionary for this user. | User |
getSecondsSinceLastActivity() | Get the amount of time, in seconds, that has elapsed since the last activity of a certain time for this user. | int |
group() | Return this user's group. | BelongsTo |
isMaster() | Returns whether or not this user is the master user. | bool |
lastActivity() | Get the most recent activity for this user, based on the user's last_activity_id. | BelongsTo |
lastActivityOfType() | Find the most recent activity for this user of a particular type. | Builder |
lastActivityTime() | Get the most recent time for a specified activity type for this user. | string|null |
onLogin() | Performs tasks to be done after this user has been successfully authenticated. | mixed |
onLogout() | Performs tasks to be done after this user has been logged out. | mixed |
passwordResets() | Get all password reset requests for this user. | HasMany |
permissions() | Get all of the permissions this user has, via its roles. | BelongsToManyThrough |
roles() | Get all roles to which this user belongs. | BelongsToMany |
scopeForRole() | Query scope to get all users who have a specific role. | Builder |
scopeJoinLastActivity() | Joins the user's most recent activity directly, so we can do things like sort, search, paginate, etc. | Builder |
buildPermissionsDictionary() | Loads permissions for this user into a cached dictionary of slugs -> arrays of permissions, so we don't need to keep requerying the DB for every call of checkAccess. | array |
__construct() | mixed | |
attributeExists() | Determine if an attribute exists on the model - even if it is null. | bool |
findUnique() | Determines whether a model exists by checking a unique column, including checking soft-deleted records. | Model|null |
relationExists() | Determine if an relation exists on the model - even if it is null. | bool |
store() | Store the object in the DB, creating a new row if one doesn't already exist. | int |
newEloquentBuilder() | Overrides Laravel's base Model to return our custom Eloquent builder object. | EloquentBuilder |
newBaseQueryBuilder() | Overrides Laravel's base Model to return our custom query builder object. | Builder |
export() | Get the properties of this object as an associative array. Alias for toArray(). | array |
queryBuilder() | For raw array fetching. Must be static, otherwise PHP gets confused about where to find $table. | Builder |
hasMany() | Overrides the default Eloquent hasMany relationship to return a HasManySyncable. | HasManySyncable |
morphMany() | Overrides the default Eloquent morphMany relationship to return a MorphManySyncable. | MorphManySyncable |
belongsToManyThrough() | Define a many-to-many 'through' relationship. | BelongsToManyThrough |
belongsToManyUnique() | Define a unique many-to-many relationship. Similar to a regular many-to-many relationship, but removes duplicate child objects. | BelongsToManyUnique |
morphToManyUnique() | Define a unique morphs-to-many relationship. Similar to a regular morphs-to-many relationship, but removes duplicate child objects. | MorphToManyUnique |
getBelongsToManyCaller() | Get the relationship name of the belongs to many. | string |
Properties
$table
The name of the table for the current model.
protected
string
$table
= 'users'
$fillable
Fields that should be mass-assignable when creating a new User.
protected
string[]
$fillable
= ['user_name', 'first_name', 'last_name', 'email', 'locale', 'theme', 'group_id', 'flag_verified', 'flag_enabled', 'last_activity_id', 'password', 'deleted_at']
$hidden
A list of attributes to hide by default when using toArray() and toJson().
protected
string[]
$hidden
= ['password']
Tags
$dates
The attributes that should be mutated to dates.
protected
string[]
$dates
= ['deleted_at']
$appends
protected
mixed
$appends
= ['full_name']
$dispatchesEvents
Events used to handle the user object cache on update and deletion.
protected
array
$dispatchesEvents
= ['saved' => \UserFrosting\Sprinkle\Account\Database\Models\Events\DeleteUserCacheEvent::class, 'deleted' => \UserFrosting\Sprinkle\Account\Database\Models\Events\DeleteUserCacheEvent::class]
$cachedPermissions
Cached dictionary of permissions for the user.
protected
array
$cachedPermissions
$timestamps
Enable timestamps for Users.
public
bool
$timestamps
= true
$id
public
int
$id
$user_name
public
string
$user_name
$first_name
public
string
$first_name
$last_name
public
string
$last_name
public
string
$email
$locale
public
string
$locale
$theme
public
string
$theme
$group_id
public
int
$group_id
$flag_verified
public
bool
$flag_verified
$flag_enabled
public
bool
$flag_enabled
$last_activity_id
public
int
$last_activity_id
$created_at
public
timestamp
$created_at
$updated_at
public
timestamp
$updated_at
$password
public
string
$password
$deleted_at
public
timestamp
$deleted_at
$ci
public
static ContainerInterface
$ci
$timestamps
public
bool
$timestamps
= false
$manyMethodsExtended
The many to many relationship methods.
public
static array
$manyMethodsExtended
= ['belongsToMany', 'morphToMany', 'morphedByMany', 'morphToManyUnique']
Methods
__isset()
Determine if the property for this object exists.
public
__isset(
$name :
string
)
: bool
We add relations here so that Twig will be able to find them. See http://stackoverflow.com/questions/29514081/cannot-access-eloquent-attributes-on-twig/35908957#35908957 Every property in __get must also be implemented here for Twig to recognize it.
Parameters
- $name : string
the name of the property to check.
Return values
bool —true if the property is defined, false otherwise.
__get()
Get a property for this object.
public
__get(
$name :
string
)
: string
Parameters
- $name : string
the name of the property to retrieve.
Tags
Return values
string —the associated property.
activities()
Get all activities for this user.
public
activities(
)
: HasMany
Return values
HasManydelete()
Delete this user from the database, along with any linked roles and activities.
public
delete(
[ $hardDelete :
bool
= false ]
)
: bool
Parameters
- $hardDelete : bool = false
Set to true to completely remove the user and all associated objects.
Return values
bool —true if the deletion was successful, false otherwise.
exists()
Determines whether a user exists, including checking soft-deleted records.
public
static exists(
$value :
mixed
[, $identifier :
string
= 'user_name' ]
[, $checkDeleted :
bool
= true ]
)
: User|null
Parameters
- $value : mixed
- $identifier : string = 'user_name'
- $checkDeleted : bool = true
set to true to include soft-deleted records
Tags
Return values
User|nullgetCache()
Return a cache instance specific to that user.
public
getCache(
)
: Store
Return values
StoregetFullNameAttribute()
Allows you to get the full name of the user using `$user->full_name`.
public
getFullNameAttribute(
)
: string
Return values
stringgetCachedPermissions()
Retrieve the cached permissions dictionary for this user.
public
getCachedPermissions(
)
: array
Return values
arrayreloadCachedPermissions()
Retrieve the cached permissions dictionary for this user.
public
reloadCachedPermissions(
)
: User
Return values
UsergetSecondsSinceLastActivity()
Get the amount of time, in seconds, that has elapsed since the last activity of a certain time for this user.
public
getSecondsSinceLastActivity(
$type :
string
)
: int
Parameters
- $type : string
The type of activity to search for.
Return values
intgroup()
Return this user's group.
public
group(
)
: BelongsTo
Return values
BelongsToisMaster()
Returns whether or not this user is the master user.
public
isMaster(
)
: bool
Return values
boollastActivity()
Get the most recent activity for this user, based on the user's last_activity_id.
public
lastActivity(
)
: BelongsTo
Return values
BelongsTolastActivityOfType()
Find the most recent activity for this user of a particular type.
public
lastActivityOfType(
[ $type :
string
= null ]
)
: Builder
Parameters
- $type : string = null
Return values
BuilderlastActivityTime()
Get the most recent time for a specified activity type for this user.
public
lastActivityTime(
$type :
string
)
: string|null
Parameters
- $type : string
Return values
string|null —The last activity time, as a SQL formatted time (YYYY-MM-DD HH:MM:SS), or null if an activity of this type doesn't exist.
onLogin()
Performs tasks to be done after this user has been successfully authenticated.
public
onLogin(
[ $params :
array
= [] ]
)
: mixed
By default, adds a new sign-in activity and updates any legacy hash.
Parameters
- $params : array = []
Optional array of parameters used for this event handler.
Tags
Return values
mixedonLogout()
Performs tasks to be done after this user has been logged out.
public
onLogout(
[ $params :
array
= [] ]
)
: mixed
By default, adds a new sign-out activity.
Parameters
- $params : array = []
Optional array of parameters used for this event handler.
Tags
Return values
mixedpasswordResets()
Get all password reset requests for this user.
public
passwordResets(
)
: HasMany
Return values
HasManypermissions()
Get all of the permissions this user has, via its roles.
public
permissions(
)
: BelongsToManyThrough
Return values
BelongsToManyThroughroles()
Get all roles to which this user belongs.
public
roles(
)
: BelongsToMany
Return values
BelongsToManyscopeForRole()
Query scope to get all users who have a specific role.
public
scopeForRole(
$query :
Builder
, $roleId :
int
)
: Builder
Parameters
- $query : Builder
- $roleId : int
Return values
BuilderscopeJoinLastActivity()
Joins the user's most recent activity directly, so we can do things like sort, search, paginate, etc.
public
scopeJoinLastActivity(
$query :
Builder
)
: Builder
Parameters
- $query : Builder
Return values
BuilderbuildPermissionsDictionary()
Loads permissions for this user into a cached dictionary of slugs -> arrays of permissions, so we don't need to keep requerying the DB for every call of checkAccess.
protected
buildPermissionsDictionary(
)
: array
Return values
array__construct()
public
__construct(
[ $attributes :
array
= [] ]
)
: mixed
Parameters
- $attributes : array = []
Return values
mixedattributeExists()
Determine if an attribute exists on the model - even if it is null.
public
attributeExists(
$key :
string
)
: bool
Parameters
- $key : string
Return values
boolfindUnique()
Determines whether a model exists by checking a unique column, including checking soft-deleted records.
public
static findUnique(
$value :
mixed
, $identifier :
string
[, $checkDeleted :
bool
= true ]
)
: Model|null
Parameters
- $value : mixed
- $identifier : string
- $checkDeleted : bool = true
set to true to include soft-deleted records
Return values
Model|nullrelationExists()
Determine if an relation exists on the model - even if it is null.
public
relationExists(
$key :
string
)
: bool
Parameters
- $key : string
Return values
boolstore()
Store the object in the DB, creating a new row if one doesn't already exist.
public
store(
)
: int
Calls save(), then returns the id of the new record in the database.
Return values
int —the id of this object.
newEloquentBuilder()
Overrides Laravel's base Model to return our custom Eloquent builder object.
public
newEloquentBuilder(
$query :
Builder
)
: EloquentBuilder
Parameters
- $query : Builder
Return values
EloquentBuildernewBaseQueryBuilder()
Overrides Laravel's base Model to return our custom query builder object.
protected
newBaseQueryBuilder(
)
: Builder
Return values
Builderexport()
Get the properties of this object as an associative array. Alias for toArray().
public
export(
)
: array
Tags
Return values
arrayqueryBuilder()
For raw array fetching. Must be static, otherwise PHP gets confused about where to find $table.
public
static queryBuilder(
)
: Builder
Tags
Return values
BuilderhasMany()
Overrides the default Eloquent hasMany relationship to return a HasManySyncable.
public
hasMany(
$related :
string
[, $foreignKey :
string
= null ]
[, $localKey :
string
= null ]
)
: HasManySyncable
Parameters
- $related : string
- $foreignKey : string = null
- $localKey : string = null
Return values
HasManySyncablemorphMany()
Overrides the default Eloquent morphMany relationship to return a MorphManySyncable.
public
morphMany(
$related :
string
, $name :
string
[, $type :
string
= null ]
[, $id :
string
= null ]
[, $localKey :
string
= null ]
)
: MorphManySyncable
Parameters
- $related : string
- $name : string
- $type : string = null
- $id : string = null
- $localKey : string = null
Return values
MorphManySyncablebelongsToManyThrough()
Define a many-to-many 'through' relationship.
public
belongsToManyThrough(
$related :
string
, $through :
string
[, $firstJoiningTable :
string
= null ]
[, $firstForeignPivotKey :
string
= null ]
[, $firstRelatedKey :
string
= null ]
[, $secondJoiningTable :
string
= null ]
[, $secondForeignPivotKey :
string
= null ]
[, $secondRelatedKey :
string
= null ]
[, $throughRelation :
string
= null ]
[, $relation :
string
= null ]
)
: BelongsToManyThrough
This is basically hasManyThrough for many-to-many relationships.
Parameters
- $related : string
- $through : string
- $firstJoiningTable : string = null
- $firstForeignPivotKey : string = null
- $firstRelatedKey : string = null
- $secondJoiningTable : string = null
- $secondForeignPivotKey : string = null
- $secondRelatedKey : string = null
- $throughRelation : string = null
- $relation : string = null
Return values
BelongsToManyThroughbelongsToManyUnique()
Define a unique many-to-many relationship. Similar to a regular many-to-many relationship, but removes duplicate child objects.
public
belongsToManyUnique(
$related :
string
[, $table :
string
= null ]
[, $foreignPivotKey :
string
= null ]
[, $relatedPivotKey :
string
= null ]
[, $parentKey :
string
= null ]
[, $relatedKey :
string
= null ]
[, $relation :
string
= null ]
)
: BelongsToManyUnique
Can also be used to implement ternary relationships.
Parameters
- $related : string
- $table : string = null
- $foreignPivotKey : string = null
- $relatedPivotKey : string = null
- $parentKey : string = null
- $relatedKey : string = null
- $relation : string = null
Return values
BelongsToManyUniquemorphToManyUnique()
Define a unique morphs-to-many relationship. Similar to a regular morphs-to-many relationship, but removes duplicate child objects.
public
morphToManyUnique(
$related :
string
, $name :
string
[, $table :
string
= null ]
[, $foreignPivotKey :
string
= null ]
[, $relatedPivotKey :
string
= null ]
[, $parentKey :
string
= null ]
[, $relatedKey :
string
= null ]
[, $inverse :
bool
= false ]
)
: MorphToManyUnique
Parameters
- $related : string
- $name : string
- $table : string = null
- $foreignPivotKey : string = null
- $relatedPivotKey : string = null
- $parentKey : string = null
- $relatedKey : string = null
- $inverse : bool = false
Return values
MorphToManyUniquegetBelongsToManyCaller()
Get the relationship name of the belongs to many.
protected
getBelongsToManyCaller(
)
: string