User
extends Model
in package
uses
HasFactory, HasApiTokens, Notifiable
User Model
This model manages user accounts and authentication for the security system. It stores user information, authentication data, profile details, and security settings including 2FA, OAuth tokens, and role-based access control.
Tags
Table of Contents
Properties
- $casts : array<string|int, mixed>
- The attributes that should be cast.
- $fillable : array<string|int, mixed>
- The attributes that are mass assignable.
- $hidden : array<string|int, mixed>
- The attributes that should be hidden for serialization.
Methods
- __construct() : void
- Create a new User model instance.
- generateToken() : string
- Generate a new authentication token for the user.
- getUserInfoWithRole() : Collection
- Get user information with role details.
- matchOldPassword() : mixed
- Match old password for password verification.
- permissions() : BelongsToMany
- Get the permissions associated with this user.
- roles() : BelongsToMany
- Get the roles associated with this user.
- google2faSecret() : Attribute
- Google 2FA secret attribute accessor/mutator.
Properties
$casts
The attributes that should be cast.
protected
array<string|int, mixed>
$casts
= ['email_verified_at' => 'datetime']
$fillable
The attributes that are mass assignable.
protected
array<string|int, mixed>
$fillable
= ['role_id', 'user_login', 'first_name', 'last_name', 'user_email', 'user_password', 'status', 'oauth_token', 'oauth_token_secret', 'remember_me', 'isDeleted', 'old_user_id', 'registration_url', 'organization', 'phone', 'address1', 'address2', 'profile_name', 'city', 'state', 'zip', 'img_path', 'img_name', 'image', 'created_by', 'updated_by', 'created_at', 'updated_at', 'authentication_2fa_status ', ' force_2fa', 'authentication_2fa_way', 'secret_key_2fa', 'google_2fa_date', 'token']
$hidden
The attributes that should be hidden for serialization.
protected
array<string|int, mixed>
$hidden
= ['password', 'remember_token']
Methods
__construct()
Create a new User model instance.
public
__construct() : void
Sets the table name from configuration constants.
generateToken()
Generate a new authentication token for the user.
public
generateToken(int $userId) : string
Creates a secure random token and stores it for the specified user.
Parameters
- $userId : int
-
User ID to generate token for
Return values
string —Generated authentication token
getUserInfoWithRole()
Get user information with role details.
public
getUserInfoWithRole(string $adminId) : Collection
This function is used to get data based for admin_id. Retrieves user information along with their role details.
Parameters
- $adminId : string
-
Admin ID of user
Return values
Collection —Collection of user data with role information
matchOldPassword()
Match old password for password verification.
public
matchOldPassword(string $adminId, string $oldPassword) : mixed
This function is used to match old password. Validates the provided old password against the stored password hash.
Parameters
- $adminId : string
-
Admin ID of user
- $oldPassword : string
-
Old password to verify
Return values
mixed —User model if password matches, false otherwise
permissions()
Get the permissions associated with this user.
public
permissions() : BelongsToMany
This function is used to check permissions for permission_id. Establishes a many-to-many relationship with the Permission model.
Return values
BelongsToManyroles()
Get the roles associated with this user.
public
roles() : BelongsToMany
This function is used to get data. Establishes a many-to-many relationship with the Role model.
Return values
BelongsToManygoogle2faSecret()
Google 2FA secret attribute accessor/mutator.
protected
google2faSecret() : Attribute
This function is used to check attribute value. Automatically encrypts/decrypts the Google 2FA secret key.