Overview
The Users API manages user accounts for the C.A.R. 911 system. It handles user creation, updates, role assignments, profile management, and theme preferences. The system uses Spatie Permission package for role-based access control.Endpoints
List Users
Retrieve a paginated list of users.Page number (100 items per page)
Array of user objects
Create User
Create a new user account with role assignment.User first name
User last name
LP number (must be unique)
National ID number
Email address (must be unique and valid)
User password
Password confirmation (must match password)
Role name to assign (from available roles)
/usuarios on success.
Error Responses
“Ya se encuentra un usuario con el mismo LP” - User with this LP already exists
- Email must be unique and valid format
- Password and confirm-password must match
- LP must be unique
- All required fields must be provided
Show User
User ID
Edit User
Get user details for editing.User ID
Update User
Update an existing user account.User ID to update
User first name
User last name
LP number
National ID
Email address (unique, excluding current user)
New password (optional, leave empty to keep current)
Password confirmation (required if password provided)
Role name to assign
/usuarios on success.
Note: When updating, if password is empty, the current password is preserved.
Delete User
Delete a user account.User ID to delete
/usuarios on success.
Profile Management
Update Profile
Update user profile information and photo.User ID to update
User name (max 255 characters)
Email address (must be unique excluding current user)
Profile photo (jpeg, png, jpg, gif, max 2MB)
- If a new photo is uploaded, the previous photo is deleted
- Photos are stored in
public/uploads/profiles/ - Filename format:
profile_{user_id}_{timestamp}.{extension}
Update Theme
Update user theme preference (light/dark mode).Theme preference: light or dark
Authentication
Login
Authentication Routes
The system uses Laravel’s built-in authentication:POST /login- Authenticate userPOST /logout- Log out userGET /password/reset- Password reset formPOST /password/email- Send password reset emailPOST /password/reset- Reset password
User Roles & Permissions
The system uses Spatie Laravel Permission package. Users can have one or more roles, and roles have associated permissions.Common Permissions
- Equipment: ver-equipo, crear-equipo, editar-equipo, borrar-equipo
- Fleet: ver-flota, crear-flota, editar-flota, borrar-flota
- Cameras: ver-camara, crear-camara, editar-camara, borrar-camara
- Bodycams: ver-bodycam, crear-bodycam, editar-bodycam, borrar-bodycam
- Dependencies: ver-dependencia, crear-dependencia, editar-dependencia, borrar-dependencia
- Users: ver-usuario, crear-usuario, editar-usuario, borrar-usuario
- Roles: ver-rol, crear-rol, editar-rol, borrar-rol
Check User Role
Error Codes
Bad Request - Validation error or missing required fields
Unauthorized - Authentication required
Forbidden - Insufficient permissions
Not Found - User not found
Unprocessable Entity - Duplicate email/LP or validation failure
Models
User Model
Represents a system user. TraitsHasApiTokens- Laravel Sanctum API tokensHasFactory- Factory supportNotifiable- Notification supportHasRoles- Spatie role management
password- Never returned in responsesremember_token- Session token
auditoria- HasMany Auditoria (audit trail)roles- BelongsToMany Role (via Spatie)permissions- BelongsToMany Permission (via Spatie)
getRoleColor($roleName)- Get color associated with role
app/Http/Controllers/UsuarioController.php:1-216
Model: app/Models/User.php:1-63