Overview
The User model represents individual users within a company. It extends Laravel’s Authenticatable class and includes role-based access control, module permissions, and soft delete functionality.Properties
Fillable Attributes
Full name of the user
Email address (used for authentication)
Foreign key to the Company this user belongs to
User role (e.g., ‘admin’, ‘developer’, ‘worker’)
Whether the user account is active
Permission flag for billing module access
Permission flag for inventory module access
Hashed password for authentication
Hidden Attributes
The following attributes are hidden from serialization:Casts
email_verified_at: Automatically cast to Carbon datetime instancepassword: Automatically hashed when set- Boolean flags are cast to true/false values
Relationships
company()
Type:BelongsTo
Returns the company this user belongs to.
inventoryMovements()
Type:HasMany
Returns all inventory movements created by this user.
billingDocuments()
Type:HasMany
Returns all billing documents created by this user.
Methods
isRole()
Check if user has a specific role.$role(string): Role name to check
bool - True if user has the specified role
canAccessModule()
Determine if user can access a specific module based on role and permissions.$module(string): Module name (‘billing’, ‘inventory’, etc.)
bool - True if user can access the module
Logic:
- Admins and developers have access to all modules
- Workers must have specific permission flags set
- Unknown modules default to true for workers
scopeForCompany()
Query scope to filter users by company.$query(Builder): Query builder instance$companyId(int|null): Company ID to filter by
Builder - Modified query builder
Traits
HasFactory: Enables model factories for testingNotifiable: Allows sending notifications to usersSoftDeletes: Enables soft deletion (deleted_at timestamp)
Usage Examples
Creating a New User
Checking User Permissions
Querying Users by Company
Accessing User Relationships
Source Reference
Model file:/home/daytona/workspace/source/app/Models/User.php