2.8 KiB
2.8 KiB
Walkthrough — Truck Status Management
We have successfully implemented the ability to edit and delete trucks from the admin dashboard, enforced Plate number read-only behavior post-creation, and automated active trip cancellation and collection team unassignment when a truck is moved to a non-active status (maintenance or retired).
Changes Made
1. Backend Changes
- Request Validation: Updated StoreTruckRequest.php to ignore the current truck's ID when validating the unique
plate_numberconstraint during updates. - Controller Logic: Extended
update()in AdminTruckController.php:- When the truck status is updated from
activeto a non-active status (maintenanceorretired), any active/scheduled trips (scheduled,in_progress,at_dumpsite) for that truck are automatically marked ascancelledwith a system note. - The truck is unassigned from any active collection teams (setting
truck_idtonullon the team).
- When the truck status is updated from
2. Frontend Changes
- Table Actions: Added an Actions column with an Edit button to the trucks list inside trucks.blade.php.
- Edit & Delete slide-over modal:
- Re-used the existing form structure for edit mode.
- Configured the plate number input field to be read-only (and visually styled as disabled) in edit mode.
- Added a Delete button at the bottom of the form when editing a truck, complete with an interactive confirm dialog.
- Form submit handler automatically switches between
POST(create) andPATCH(update) based on the context.
Verification Results
Automated Tests
Created and ran a new test file: AdminTruckCrudTest.php
All test cases pass successfully:
PASS Tests\Feature\Api\V1\Admin\AdminTruckCrudTest
✓ admin can update truck details 14.39s
✓ admin updating plate uniqueness checks 0.16s
✓ changing status to maintenance cancels trips and unassigns teams 0.18s
✓ admin can delete truck 0.10s
Tests: 4 passed (13 assertions)
Duration: 15.17s
Frontend Assets
Built the frontend assets successfully via Vite compilation:
✓ built in 3.40s