Overview
TheUser model represents authenticated users in the system, including doctors, receptionists, admin staff, and patients. It extends Laravel’s Authenticatable class and integrates with Fortify for authentication and Spatie Permission for role-based access control.
Model Location: app/Models/User.phpDatabase Table:
users
Database Schema
Primary key, auto-incrementing
User’s full name (max 255 characters)
User’s email address (unique, used for login)
Timestamp when email was verified (nullable)
Hashed password (automatically hashed by Laravel)
Encrypted two-factor authentication secret
Encrypted two-factor recovery codes
Timestamp when two-factor authentication was confirmed
Token for “remember me” functionality
Record creation timestamp
Record last update timestamp
Fillable Attributes
Only these attributes can be mass-assigned:Hidden Attributes
These attributes are hidden from JSON serialization for security:Type Casting
Traits
The User model uses the following traits:- HasFactory: Enables model factories for testing
- Notifiable: Adds notification sending capabilities
- TwoFactorAuthenticatable: Adds two-factor authentication via Laravel Fortify
- HasRoles: Adds role and permission management via Spatie Permission
Roles
Users can have one of four roles:Admin
Full system access including staff management and reports
Doctor
Manage appointments, consultations, prescriptions, and schedules
Receptionist
Manage patients, appointments, and payments
Patient
Self-service portal for appointments and medical records
Usage Examples
Creating a User
Checking User Role
Querying by Role
Two-Factor Authentication
Sending Notifications
Relationships
While not explicitly defined in the User model, the following relationships exist:Doctor Schedules
Consultations (as Doctor)
Appointments (as Doctor)
Security Considerations
Email verification is available through Laravel Fortify. Enable it in
config/fortify.php to require users to verify their email before accessing the system.