Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/alber1802/AvaluoVehicular/llms.txt

Use this file to discover all available pages before exploring further.

When an evaluator or admin deletes a vehicle in Avalúo Vehicular, the record is not immediately erased — it is soft-deleted, meaning it is hidden from normal queries but still present in the database with a deleted_at timestamp. The recycle bin (/reciclaje) provides a dedicated interface to browse those hidden records, restore them to their original state, or permanently erase them when they are no longer needed. Evaluators see only their own deleted vehicles; administrators see the full list across all evaluators, along with statistics on how many records were deleted this calendar month.

How Soft Deletes Work

Laravel’s SoftDeletes trait adds a deleted_at column to a model’s table. When $model->delete() is called, Eloquent sets deleted_at to the current timestamp instead of executing a DELETE statement. All standard Eloquent queries automatically add a WHERE deleted_at IS NULL clause, so soft-deleted rows are invisible to the rest of the application until explicitly requested. To query soft-deleted records, use:
// Only trashed records
Vehiculo::onlyTrashed()->get();

// All records including trashed
Vehiculo::withTrashed()->find($id);

Models That Support Soft Deletes

Both of the core domain models use SoftDeletes:
ModelTableTrait
App\Models\VehiculovehiculosIlluminate\Database\Eloquent\SoftDeletes
App\Models\AvaluoavaluoIlluminate\Database\Eloquent\SoftDeletes
When a vehicle is soft-deleted through the recycle bin’s destroy route, the controller also soft-deletes every related record in a single operation — condicionGeneral, inspecciones, sistemas, accesorios, archivos, imagenes, and avaluo — as well as any AvaluoCompartido entries linked to the vehicle’s appraisal. The same cascade logic runs in reverse during a restore.

Routes

All routes are grouped under the /reciclaje prefix and require the auth and verified middleware.

List Soft-Deleted Records

GET /reciclaje/listado
Fetches all soft-deleted Vehiculo records using onlyTrashed(), with eager-loaded marca and evaluador relationships. Each record in the response includes:
  • id, entidad, marca, modelo, año_fabricacion, placa
  • fecha_evaluacion, deleted_at (formatted Y-m-d)
  • id_evaluador, nombre_evaluador, email_evaluador
Admins also receive a usuarios array (unique evaluator IDs and names for filtering) and a stats object with total, eliminados_mes (deleted this month), and por_evaluador counts.

Restore a Record

GET /reciclaje/restore/{id}
The route is declared with .withTrashed() so Laravel does not filter out soft-deleted records when resolving the route model. The controller calls Vehiculo::onlyTrashed()->findOrFail($id) and then cascades ->restore() to every related sub-model and the appraisal itself.
$vehiculo->condicionGeneral()->restore();
$vehiculo->inspecciones()->restore();
$vehiculo->sistemas()->restore();
$vehiculo->accesorios()->restore();
$vehiculo->archivos()->restore();
$vehiculo->imagenes()->restore();
$vehiculo->avaluo()->restore();
$vehiculo->restore();
Any AvaluoCompartido rows that were soft-deleted alongside the appraisal are also restored.

Soft Delete (Move to Bin)

DELETE /reciclaje/destroy/{id}
Soft-deletes a vehicle and its entire relationship tree. Evaluators can only delete their own vehicles; admins can delete any vehicle. After deletion the user is redirected to the dashboard.

Force Delete (Permanent)

DELETE /reciclaje/forceDelete/{id}
Permanently removes the vehicle and all related records from the database. This route is admin-only — non-admins are redirected with an error. The route is declared with .withTrashed() so it can resolve records that have already been soft-deleted. For archivos and imagenes, the controller additionally deletes the associated files from the public storage disk before force-deleting the database rows:
Storage::disk('public')->delete($vehiculo->archivos()->first()->url);
// ... then forceDelete the rows
forceDelete is irreversible. Once a vehicle is permanently deleted, its record, all inspection data, appraisal values, attached files, images, and shared appraisal links are gone forever and cannot be recovered. Use this operation only when you are certain the data is no longer needed.

Restore a Vehicle

1

Navigate to the recycle bin

Go to /reciclaje/listado. The page displays a table of all soft-deleted vehicles visible to your account, along with deletion date and the evaluator who owned the record.
2

Find the deleted vehicle

Use the evaluator filter (admins only) or scroll to locate the vehicle by brand, model, plate, or deletion date. The deleted_at column shows when it was moved to the bin.
3

Click Restore

Click the Restaurar action for the target vehicle. This triggers GET /reciclaje/restore/{id}, which cascades the restore across the vehicle’s inspections, condition records, systems, accessories, files, images, appraisal, and any shared appraisal links.
4

Confirm the recovery

You are redirected to the dashboard with a "Vehículo restaurado correctamente" success message. The vehicle and all its associated appraisal data are fully accessible again through the normal registration and appraisal views.
Periodically clean up old soft-deleted records to keep the recycle bin manageable and free storage space occupied by attached files and images. A good practice is to audit deleted records at the end of each month and permanently erase anything older than 30 days that will not be needed again.

Operations Reference

OperationRouteAccess
List deleted recordsGET /reciclaje/listadoAdmin (all), Evaluator (own)
Restore a recordGET /reciclaje/restore/{id}Admin (all), Evaluator (own)
Soft delete (move to bin)DELETE /reciclaje/destroy/{id}Admin (all), Evaluator (own)
Permanently deleteDELETE /reciclaje/forceDelete/{id}Admin only

Build docs developers (and LLMs) love