Overview
This page documents the main controllers for managing clients and vehicles in the VIP2CARS system. Both controllers follow Laravel’s resource controller pattern with standard CRUD operations.ClienteController
Namespace:App\Http\Controllers
Location: app/Http/Controllers/ClienteController.php
Handles all client-related operations including creating, reading, updating, and deleting client records.
Methods
index()
Display a listing of all clients. Signature:clientes.index with all clients
Implementation:
create()
Show the form for creating a new client. Signature:clientes.create
Implementation:
store()
Store a newly created client in the database. Signature:HTTP request containing client data
- Rules:
required|string|max:255 - Client’s first name(s)
- Rules:
required|string|max:255 - Client’s last name(s)
- Rules:
required|string|unique:clientes,nro_documento - Document number (must be unique)
- Rules:
required|email|unique:clientes,correo - Email address (must be valid and unique)
- Rules:
required|string|max:20 - Phone number
clientes.index with success message
Implementation:
show()
Display the specified client. Signature:Client ID (id_cliente)
clientes.show with client data
Throws: ModelNotFoundException if client not found
Implementation:
edit()
Show the form for editing the specified client. Signature:Client ID (id_cliente)
clientes.edit with client data
Throws: ModelNotFoundException if client not found
Implementation:
update()
Update the specified client in the database. Signature:HTTP request containing updated client data
Client ID (id_cliente)
- Rules:
required|string|max:255
- Rules:
required|string|max:255
- Rules:
required|string|unique:clientes,nro_documento,{id},id_cliente - Unique except for current client
- Rules:
required|email|unique:clientes,correo,{id},id_cliente - Unique except for current client
- Rules:
required|string|max:20
clientes.index with success message
Throws: ModelNotFoundException if client not found
Implementation:
destroy()
Remove the specified client from the database. Signature:Client ID (id_cliente)
clientes.index with success message
Throws: ModelNotFoundException if client not found
Implementation:
VehiculoController
Namespace:App\Http\Controllers
Location: app/Http/Controllers/VehiculoController.php
Handles all vehicle-related operations including creating, reading, updating, and deleting vehicle records.
Methods
index()
Display a listing of all vehicles with their owner information. Signature:vehiculos.index with all vehicles (eager-loaded with cliente relationship)
Implementation:
create()
Show the form for creating a new vehicle. Signature:vehiculos.create with list of all clients
Implementation:
store()
Store a newly created vehicle in the database. Signature:HTTP request containing vehicle data
- Rules:
required|string|unique:vehiculos,placa - License plate (must be unique)
- Rules:
required|string|max:255 - Vehicle brand/manufacturer
- Rules:
required|string|max:255 - Vehicle model
- Rules:
required|numeric|digits:4 - Year of manufacture (must be 4 digits)
- Rules:
required|exists:clientes,id_cliente - Must reference an existing client
vehiculos.index with success message
Implementation:
show()
Display the specified vehicle with owner information. Signature:Vehicle ID (id_vehiculo)
vehiculos.show with vehicle data (eager-loaded with cliente relationship)
Throws: ModelNotFoundException if vehicle not found
Implementation:
edit()
Show the form for editing the specified vehicle. Signature:Vehicle ID (id_vehiculo)
vehiculos.edit with vehicle data and list of all clients
Throws: ModelNotFoundException if vehicle not found
Implementation:
update()
Update the specified vehicle in the database. Signature:HTTP request containing updated vehicle data
Vehicle ID (id_vehiculo)
- Rules:
required|string|unique:vehiculos,placa,{id},id_vehiculo - Unique except for current vehicle
- Rules:
required|string|max:255
- Rules:
required|string|max:255
- Rules:
required|numeric|digits:4
- Rules:
required|exists:clientes,id_cliente
vehiculos.index with success message
Throws: ModelNotFoundException if vehicle not found
Implementation:
destroy()
Remove the specified vehicle from the database. Signature:Vehicle ID (id_vehiculo)
vehiculos.index with success message
Throws: ModelNotFoundException if vehicle not found
Implementation:
Common Patterns
Error Handling
Error Handling
Both controllers use
findOrFail() which automatically throws a ModelNotFoundException (404 error) when a record is not found. Laravel handles this exception and returns a 404 page.Flash Messages
Flash Messages
All create, update, and delete operations redirect with a success flash message that can be displayed to users:
'Cliente creado correctamente.''Cliente actualizado correctamente.''Cliente eliminado correctamente.''Vehículo creado correctamente.''Vehículo actualizado correctamente.''Vehículo eliminado correctamente.'
Eager Loading
Eager Loading
The VehiculoController uses eager loading with
with('cliente') to avoid N+1 query problems when displaying vehicle lists with owner information.Related Documentation
- Cliente Model - Cliente model reference
- Vehiculo Model - Vehiculo model reference