Overview
TheClinicaController handles all clinic management operations for the DentControl SaaS platform. This controller is exclusively for superadmin use and provides functionality to create, read, update, and manage the status of dental clinics. It includes comprehensive validation, logo upload handling, and status toggle capabilities.
Location: app/Http/Controllers/Admin/ClinicaController.php
Namespace: App\Http\Controllers\Admin
Methods
index()
Displays a list of all clinics ordered by most recent first. Route:GET /clinicas
Route Name: clinicas.index
Middleware:
auth- User must be authenticatedcan:admin-only- User must have superadmin role
admin.clinicas.index Blade view with:
Collection of all clinics ordered by
created_at DESCstore()
Creates a new clinic with comprehensive validation and optional logo upload. Route:POST /clinicas
Route Name: clinicas.store
Middleware:
authcan:admin-only
Clinic name (max 50 chars, letters, numbers, spaces, &, ’, -)
Mexican RFC tax ID (12-13 chars, uppercase, unique)Format:
ABCD123456EF7 (3-4 letters + 6 digits + 3 alphanumeric)Street name (max 255 chars)
External street number (max 10 chars)
Internal/apartment number (max 10 chars)
Neighborhood/colony (max 255 chars)
5-digit postal code
City name
State name
10-digit phone number (numeric, unique)
Clinic logo image (jpeg, png, jpg, max 2MB)
nombre.max: “El nombre no debe exceder los 50 caracteres.”nombre.regex: “El nombre solo permite letras, números y espacios.”rfc.unique: “Este RFC ya está registrado.”rfc.min: “El RFC debe tener al menos 12 caracteres.”telefono.digits: “El teléfono debe ser de 10 dígitos.”codigo_postal.digits: “El código postal debe ser de 5 dígitos.”rfc.regex: “El formato del RFC es inválido (Ej: ABCD123456EF7).”
clinicas.index with success message: “Clínica registrada correctamente.”
Logo Upload:
- Stored in:
public/images/logos/ - Filename format:
logo_{timestamp}.{extension} - Database stores:
images/logos/{filename}
edit()
Retrieves a specific clinic’s data for editing (AJAX endpoint). Route:GET /clinicas/{id}/edit
Route Name: clinicas.edit
Middleware:
authcan:admin-only
Clinic ID (
id_clinica)- 404 Not Found if clinic doesn’t exist
update()
Updates an existing clinic with validation and optional logo replacement. Route:PUT /clinicas/{id}
Route Name: clinicas.update
Middleware:
authcan:admin-only
Clinic ID (
id_clinica)Clinic name (max 50 chars)
RFC tax ID (unique, excluding current clinic)
Street name
External number
Internal number
Neighborhood
5-digit postal code
City name
State name
10-digit phone (unique, excluding current clinic)
New clinic logo (replaces existing)
store(), but with unique exceptions:
rfc.unique: “Este RFC ya pertenece a otra clínica registrada.”telefono.unique: “Este número telefónico ya está asociado a otra clínica.”
- If new logo uploaded:
- Deletes old logo file from disk (if exists)
- Uploads new logo with timestamp filename
- Updates
logo_rutafield
- If no new logo:
- Keeps existing logo path
clinicas.index with message: “Clínica actualizada correctamente.”
Validation Failure:
Redirects back with:
- Error messages
- Input data preserved
editing_clinic_idsession variable (for modal reopening)
toggleStatus()
Toggles a clinic’s status between active and inactive. Route:PATCH /clinicas/{id}/toggle
Route Name: clinicas.toggle
Middleware:
authcan:admin-only
Clinic ID (
id_clinica)- If
estatus = 'activo'→ changes to'baja' - If
estatus = 'baja'→ changes to'activo'
'activo': “Clínica reactivada con éxito.”'baja': “Clínica dada de baja.”
- When a clinic is set to
'baja', associated users cannot log in - The
AuthControllerchecks clinic status during login
Summary
TheClinicaController provides 5 methods for complete clinic management:
- index() - List all clinics (ordered by newest)
- store() - Create new clinic with logo upload
- edit() - Get clinic data (JSON for AJAX)
- update() - Update clinic with logo replacement
- toggleStatus() - Activate/deactivate clinic
- Comprehensive RFC and phone validation
- Logo upload and management
- Duplicate prevention (RFC, phone)
- Status toggling with user login impact
- Custom error messages in Spanish
- Modal-friendly edit/validation flow
- File cleanup on logo replacement