Overview
TheCasosController manages legal cases in the Sistema de Abogados application. It handles case creation, updates, deletion, search functionality, and relationship management with processes and opposing parties.
Namespace: App\Http\Controllers
Extends: Controller
Dependencies
The controller uses the following models:Casos- Main case modelCliente- Client modelTipoProceso- Process type modelParteContraria- Opposing party modelCaso_has_proceso- Case-Process pivot modelCaso_has_PContraria- Case-Opposing party pivot modelCasoDocumento- Case document model
Methods
index()
Lists all cases with pagination and search functionality. Purpose: Display a paginated list of cases with optional search filtering Parameters: None (usesrequest('search') for search query)
Returns: View caso.caso.index with cases and clients
Response Data:
Paginated collection of cases (5 per page)
All clients for filtering/assignment
caso.caso.index
create()
Displays the case creation form. Purpose: Show the form for creating a new case Parameters: None Returns: Viewcaso.caso.create with clients
Response Data:
All available clients to assign to the case
caso.caso.create
store()
Creates a new case with validation. Purpose: Store a new case in the database Request Parameters:Case number or identifier
Case start date
Case end date (optional)
Case description (optional)
Case status
Client ID associated with the case
caso.caso.index with success message
Success Message: “Caso registrado correctamente.”
Code Example:
caso.caso.store
show()
Displays detailed information for a specific case. Purpose: Show complete case details including processes, opposing parties, and documents Parameters:Case model instance (route model binding)
caso.caso.caso with case data and related entities
Response Data:
The case instance
All available process types
Process types assigned to cases
All opposing parties
Opposing parties assigned to cases
Documents associated with cases
caso.caso.show
edit()
Displays the case edit form. Purpose: Show the form for editing an existing case Parameters:Case model instance (route model binding)
caso.caso.edit with case and clients
Response Data:
The case instance to edit
All available clients
caso.caso.edit
update()
Updates an existing case with validation. Purpose: Update case information in the database Parameters:Case model instance (route model binding)
Case number or identifier
Case start date
Case end date (optional)
Case description (optional)
Case status
Client ID (optional on update)
caso.caso.index with success message
Success Message: “Caso Actualisado correctamente.”
Code Example:
caso.caso.update
destroy()
Deletes a case from the database. Purpose: Remove a case with foreign key constraint handling Parameters:Case model instance (route model binding)
- Success: Redirect to
caso.caso.indexwith success message - Error: Back with alert message if constraints exist
caso.caso.destroy
Notes:
- Uses try-catch to handle foreign key constraint violations
- Related entities must be removed before deleting the case
assignProceso()
Assigns a process type to a case. Purpose: Create a relationship between a case and a process type Parameters:Case model instance (route model binding)
Process type ID to assign
- Automatically sets
id_casofrom the route parameter - Creates a pivot table entry
removeProceso()
Removes a process type assignment from a case. Purpose: Delete the relationship between a case and a process type Parameters:Case-process pivot model instance (route model binding)
assignPContraria()
Assigns an opposing party to a case. Purpose: Create a relationship between a case and an opposing party Parameters:Case model instance (route model binding)
Opposing party ID to assign
- Automatically sets
id_casofrom the route parameter - Creates a pivot table entry
removePContraria()
Removes an opposing party assignment from a case. Purpose: Delete the relationship between a case and an opposing party Parameters:Case-opposing party pivot model instance (route model binding)
Usage Examples
Creating a New Case
Updating a Case
Assigning a Process Type
Searching Cases
Error Handling
Deletion Constraints
When attempting to delete a case with related records:Validation Errors
Laravel’s validation will automatically return error messages for:- Missing required fields
- Invalid data formats
- Type mismatches
Related Models
- Casos - Main case model at
/home/daytona/workspace/source/app/Models/Casos.php - Cliente - Client model
- TipoProceso - Process types for case categorization
- ParteContraria - Opposing parties in cases
- CasoDocumento - Documents attached to cases