Overview
The Document Management system provides secure storage and organization for all case and expediente documents. The system supports PDF file uploads with comprehensive metadata, secure access via UUIDs, and organized storage paths. Each document type (case documents and expediente documents) has its own model, controller, and storage structure.Secure Document Storage
Documents are stored securely with UUID-based access control, preventing unauthorized viewing or downloading.
Rich Metadata
Each document includes type classification, descriptions, and expediente-specific fields like acta numbers and folio information.
Dual Document Systems
Separate document management for casos (legal cases) and expedientes (conciliation processes) with tailored metadata.
View and Download
Documents can be viewed in-browser or downloaded for offline access with secure URL routing.
Document Types
The system manages two distinct document categories:Case Documents (CasoDocumento)
Documents attached to legal cases (casos), stored in/public/documentoCaso/
Expediente Documents (ExpedienteDocumento)
Documents attached to conciliation expedientes, stored in/public/documento/
Both document types use identical upload, view, download, and deletion processes, but have different metadata fields and storage locations.
Case Document Structure
Each CasoDocumento record contains:| Field | Description | Required |
|---|---|---|
| uuid | Unique identifier for secure access | Auto-generated |
| tipo_documento | Document type/category | Yes |
| descripcion | Document description or notes | Optional |
| documento | Stored filename | Auto-generated |
| id_caso | Associated case ID (foreign key) | Yes |
Document Type Examples
- Demand letters
- Court filings
- Evidence documents
- Client correspondence
- Legal opinions
- Contracts
- Settlement agreements
- Court orders
Expediente Document Structure
Each ExpedienteDocumento record contains:| Field | Description | Required |
|---|---|---|
| uuid | Unique identifier for secure access | Auto-generated |
| tipo_documento | Document type/category | Yes |
| n_acta | Acta (minutes) number | Optional |
| folio | Folio number for record keeping | Optional |
| tipo_acta | Type of acta document | Optional |
| descripcion | Document description or notes | Optional |
| documento | Stored filename | Auto-generated |
| id_expediente | Associated expediente ID (foreign key) | Yes |
Expediente Document Type Examples
- Conciliation requests
- Session minutes (actas)
- Party responses
- Evidence submissions
- Agreement drafts
- Final agreements
- Closure actas
- Attendance records
Uploading Documents
The upload process is similar for both document types:Upload Requirements
- File Format: PDF only (
.pdf) - Maximum Size: 15,200 KB (approximately 15 MB)
- File Validation: System validates format and size before upload
Case Document Upload Process
-
Navigate to Case
- Open the specific case detail page
- Locate the Documents section
-
Access Upload Form
- Click “Upload Document” or “Add Document”
- Routed to
/caso/caso/{caso}/file
-
Complete Upload Form
- Document Type (
tipo_documento): Select or enter document category - Description (
descripcion): Add notes about the document - File Selection: Choose PDF file from your device
- Document Type (
-
Submit Upload
- System validates file format (must be PDF)
- System checks file size (max 15 MB)
- File is renamed with timestamp prefix for uniqueness
- Document is saved to
/public/documentoCaso/ - UUID is auto-generated for secure access
- Record is linked to case via
id_caso
-
Confirmation
- Success message: “Documento registrado correctamente.”
- Redirected to case index page
- Document appears in case document list
Expediente Document Upload Process
-
Navigate to Expediente
- Open the specific expediente detail page
- Locate the Documents section
-
Access Upload Form
- Click “Upload Document”
- Routed to
/conciliacion/expediente/{expediente}/file
-
Complete Upload Form
- Document Type (
tipo_documento): Select document category - Acta Type (
tipo_acta): If applicable, specify acta type - Acta Number (
n_acta): Sequential number for minutes - Folio (
folio): Record-keeping folio number - Description (
descripcion): Add notes about the document - File Selection: Choose PDF file from device
- Document Type (
-
Submit Upload
- System validates file format and size
- File renamed with timestamp for uniqueness
- Document saved to
/public/documento/ - UUID auto-generated
- Record linked to expediente via
id_expediente
-
Confirmation
- Success message: “Documento registrado correctamente.”
- Redirected to expediente index
- Document appears in expediente document list
The system automatically generates a unique filename by prepending a timestamp to the original filename. This prevents filename conflicts and maintains file integrity.
Viewing Documents
Documents can be viewed directly in the browser:In-Browser Viewing
For Case Documents:- Route:
GET /caso/caso/file/{uuid} - Click “View” next to any document
- PDF opens in browser window
- Uses Laravel’s
response()->file()method
- Route:
GET /conciliacion/expediente/file/{uuid} - Click “View” next to any document
- PDF opens in browser window
Security Features
- Access via UUID (not filename) prevents direct file access
- System verifies document exists before serving
- 404 error if UUID not found
- Respects Laravel authentication middleware
Downloading Documents
Download documents for offline access or sharing:Download Process
For Case Documents:- Route:
GET /caso/caso/file/download/{uuid} - Click “Download” next to document
- Browser prompts file download
- Original filename is preserved
- Route:
GET /conciliacion/expediente/file/download/{uuid} - Click “Download” button
- File downloads with original name
How Downloads Work
- User clicks download link
- System looks up document by UUID
- System retrieves file path from database
- Laravel’s
response()->download()serves file - Browser receives file with proper headers
- User saves file locally
Downloaded files retain their original names (with timestamp prefix). This helps users identify files when saving multiple documents.
Editing Document Metadata
Update document information without re-uploading the file:Case Document Edit Process
-
Access Edit Form
- From case detail page, click “Edit” next to document
- Route:
GET /caso/caso/file/{id}/edit
-
Update Metadata
- Modify document type
- Update description
- Optionally replace the PDF file
-
File Replacement (Optional)
- If new file uploaded:
- Old file is deleted from storage
- New file is saved with timestamp
- Filename updated in database
- If no new file:
- Existing file remains unchanged
- Only metadata is updated
- If new file uploaded:
-
Save Changes
- Route:
PUT /caso/caso/{id}/file - Success message: “Documento Actualisado correctamente.”
- Redirected to case index
- Route:
Expediente Document Edit Process
-
Access Edit Form
- From expediente detail, click “Edit” next to document
- Route:
GET /conciliacion/expediente/file/{id}/edit
-
Update Metadata
- Modify document type, acta type, acta number, folio
- Update description
- Optionally replace PDF file
-
File Replacement
- Same process as case documents
- Old file deleted if new file uploaded
- Filename updated accordingly
-
Save Changes
- Route:
PUT /conciliacion/expediente/{id}/file - Success message displayed
- Redirected to expediente index
- Route:
Deleting Documents
Remove documents from cases or expedientes:Deletion Process
For Case Documents:- Navigate to case detail page
- Locate document in documents list
- Click “Delete” button
- System performs deletion:
- Checks if physical file exists in
/public/documentoCaso/ - Deletes physical file from storage
- Deletes database record
- Checks if physical file exists in
- Success message: “Documento eliminado correctamente.”
- Returns to previous page
- Navigate to expediente detail page
- Locate document in list
- Click “Delete”
- System performs deletion:
- Checks if file exists in
/public/documento/ - Deletes physical file
- Deletes database record
- Checks if file exists in
- Success message displayed
- Returns to previous page
Deletion Safety
- Physical file is deleted only if it exists (prevents errors)
- Database record is always deleted
- Deletion is permanent and cannot be undone
- No cascading effects on case or expediente
UUID-Based Security
The system uses UUIDs for document access control:What are UUIDs?
Universally Unique Identifiers (UUIDs) are 36-character strings like:Security Benefits
-
Unpredictable Access
- URLs cannot be guessed or enumerated
- Sequential ID scanning is prevented
-
Secure Sharing
- Documents can be shared via UUID links
- Links don’t reveal case or expediente IDs
-
Access Control
- Combined with authentication middleware
- Only authenticated users can access documents
- Role-based access restrictions apply
UUID Generation
UUIDs are automatically generated using Laravel’sStr::orderedUuid():
- Generated during document upload
- Stored in database
uuidfield - Used in all view and download routes
Ordered UUIDs maintain time-based ordering while providing security. This helps with database indexing and performance.
File Storage Structure
Case Documents
- Storage Path:
/public/documentoCaso/ - Filename Format:
{timestamp}_{original_filename}.pdf - Example:
1679234567_demand_letter.pdf
Expediente Documents
- Storage Path:
/public/documento/ - Filename Format:
{timestamp}_{original_filename}.pdf - Example:
1679234890_acta_session_01.pdf
Storage Best Practices
Regular Backups
Regular Backups
Implement regular backups of both storage directories:
/public/documentoCaso/for case documents/public/documento/for expediente documents
Storage Monitoring
Storage Monitoring
Monitor disk space usage:
- Track total storage consumption
- Set alerts for low disk space
- Implement storage quotas if needed
- Review and archive old documents periodically
File Permissions
File Permissions
Ensure proper file permissions:
- Web server must have write access to storage directories
- Files should not be executable
- Restrict direct URL access (use routing only)
- Implement proper
.htaccessor nginx rules
Disaster Recovery
Disaster Recovery
Prepare for data loss scenarios:
- Maintain offsite backups
- Document restore procedures
- Test recovery process regularly
- Keep backup-database synchronization
Role-Based Access
Case Documents Access
Available to roles with case management access:| Role | Access Level |
|---|---|
| Encargado | Full access - upload, view, edit, delete |
| Admin | Full access - upload, view, edit, delete |
| Abogado | Full access - upload, view, edit, delete |
| Asistente | No access |
Expediente Documents Access
Available to roles with expediente management access:| Role | Access Level |
|---|---|
| Encargado | Full access - upload, view, edit, delete |
| Admin | Full access - upload, view, edit, delete |
| Asistente | Full access - upload, view, edit, delete |
| Abogado | No access |
Document access follows the same role restrictions as the parent module (cases or expedientes). This maintains consistent security boundaries.
Document Organization Best Practices
Limitations and Constraints
File Format Limitation
- PDF Only: System accepts only PDF files
- Other formats (Word, images, etc.) must be converted to PDF before upload
- This ensures consistent viewing across all devices and browsers
File Size Limit
- Maximum Size: 15,200 KB (≈15 MB)
- Large files must be compressed or split
- Configuration can be modified in controller validation rules
Storage Capacity
- Limited by server disk space
- Monitor usage regularly
- Implement archival strategy for old documents
Technical Implementation
For developers and system administrators:Case Documents
Model:app/Models/CasoDocumento.php
Controller: app/Http/Controllers/CasoDocumentoController.php
Routes:
- Create form:
GET /caso/caso/{caso}/file - Upload:
POST /caso/caso/{caso} - Edit form:
GET /caso/caso/file/{id}/edit - Update:
PUT /caso/caso/{id}/file - Delete:
DELETE /caso/caso/{caso}/file - Download:
GET /caso/caso/file/download/{uuid} - View:
GET /caso/caso/file/{uuid}
/public/documentoCaso/
Table: caso_documentos
Expediente Documents
Model:app/Models/ExpedienteDocumento.php
Controller: app/Http/Controllers/ExpedienteDocumentosController.php
Routes:
- Create form:
GET /conciliacion/expediente/{expediente}/file - Upload:
POST /conciliacion/expediente/{expediente} - Edit form:
GET /conciliacion/expediente/file/{id}/edit - Update:
PUT /conciliacion/expediente/{id}/file - Delete:
DELETE /conciliacion/expediente/{expediente}/file - Download:
GET /conciliacion/expediente/file/download/{uuid} - View:
GET /conciliacion/expediente/file/{uuid}
/public/documento/
Table: expediente_documentos
Key Implementation Details
- File Validation: Uses Laravel’s validation rules
['required', 'mimes:pdf', 'max:15200'] - File Storage: Laravel’s
move()method stores files in public directories - UUID Generation:
Str::orderedUuid()creates time-ordered UUIDs - File Deletion:
File::exists()andFile::delete()manage physical files - Filename Format:
time().'_'.$file->getClientOriginalName()