Overview
Clients are managed through theClienteController located at app/Http/Controllers/ClienteController.php:7. The system uses the Cliente model with a custom primary key id_cliente and stores data in the clientes table.
Model Structure
TheCliente model includes the following fields:
nombres
Client’s first name(s) - Required, string, max 255 characters
apellidos
Client’s last name(s) - Required, string, max 255 characters
nro_documento
Document number - Required, unique, string
correo
Email address - Required, unique, valid email format
telefono
Phone number - Required, string, max 20 characters
id_cliente
Primary key - Auto-generated
CRUD Operations
Listing Clients
Retrieve all clients from the database. Route:GET /clientes
Controller Method: ClienteController::index() at line 12
Creating a Client
Create Form
Create Form
Route:
GET /clientes/createController Method: ClienteController::create() at line 18Displays the client creation form with all required fields.Store Client
Store Client
Route: Success Response: Redirects to
POST /clientesController Method: ClienteController::store() at line 23Validates and stores a new client in the database.clientes.index with success message “Cliente creado correctamente.”Viewing a Client
Route:GET /clientes/{id}
Controller Method: ClienteController::show() at line 38
The system uses
findOrFail() which automatically returns a 404 error if the client doesn’t exist.Updating a Client
Edit Form
Edit Form
Route:
GET /clientes/{id}/editController Method: ClienteController::edit() at line 44Displays the client edit form pre-filled with existing data.Update Client
Update Client
Route: Success Response: Redirects to
PUT/PATCH /clientes/{id}Controller Method: ClienteController::update() at line 50Validates and updates an existing client record.clientes.index with success message “Cliente actualizado correctamente.”Deleting a Client
Route:DELETE /clientes/{id}
Controller Method: ClienteController::destroy() at line 67
Relationships
TheCliente model has a one-to-many relationship with vehicles defined at app/Models/Cliente.php:20:
- A single client can own multiple vehicles
- Access a client’s vehicles using
$cliente->vehiculos - The relationship is keyed by
id_clienteon both tables
Validation Rules
On Create
| Field | Rules | Description |
|---|---|---|
nombres | required, string, max:255 | Client’s first name(s) |
apellidos | required, string, max:255 | Client’s last name(s) |
nro_documento | required, string, unique:clientes,nro_documento | Unique document number |
correo | required, email, unique:clientes,correo | Unique email address |
telefono | required, string, max:20 | Phone number |
On Update
Update validation is identical to create validation, except unique rules exclude the current record:
unique:clientes,nro_documento,{id},id_clienteunique:clientes,correo,{id},id_cliente
Route Protection
All client management routes are protected by middleware defined inroutes/web.php:12:
RESTful Resource Routes
TheRoute::resource() declaration automatically creates these routes:
| Method | URI | Action | Route Name |
|---|---|---|---|
| GET | /clientes | index | clientes.index |
| GET | /clientes/create | create | clientes.create |
| POST | /clientes | store | clientes.store |
| GET | /clientes/ | show | clientes.show |
| GET | /clientes//edit | edit | clientes.edit |
| PUT/PATCH | /clientes/ | update | clientes.update |
| DELETE | /clientes/ | destroy | clientes.destroy |