- Migration: add current_load_kg (nullable unsigned int) to trips table
- Trip model: add current_load_kg to fillable + integer cast
- New TruckLoadBroadcast event (ShouldBroadcastNow)
- Channel: private admin.live
- Event name: truck.load
- Payload: trip_id, team_id, truck_id, current_load_kg, capacity_kg, is_full
- DriverTripController::updateLoad()
- PATCH /api/v1/driver/trips/{trip}/update-load
- Validates status is in_progress, saves current_load_kg, fires broadcast
- Route: PATCH driver/trips/{trip}/update-load registered
- CollectionTeamResource: truck_is_full uses current_load_kg (live estimate)
with fallback to total_load_kg (authoritative dumpsite weight)
- TripResource: expose current_load_kg field
- Admin Teams card:
- data-team-id attribute added to each card for Echo targeting
- Load bar uses current_load_kg when available
- Echo listener for truck.load event patches load bar + badge in real-time
- truck-status-badge class added to Collecting/Truck Full spans
45 lines
1.2 KiB
PHP
45 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Events;
|
|
|
|
use App\Models\Trip;
|
|
use Illuminate\Broadcasting\InteractsWithSockets;
|
|
use Illuminate\Broadcasting\PrivateChannel;
|
|
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
|
|
use Illuminate\Foundation\Events\Dispatchable;
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
class TruckLoadBroadcast implements ShouldBroadcastNow
|
|
{
|
|
use Dispatchable, InteractsWithSockets, SerializesModels;
|
|
|
|
public function __construct(public readonly Trip $trip) {}
|
|
|
|
public function broadcastOn(): array
|
|
{
|
|
return [new PrivateChannel('admin.live')];
|
|
}
|
|
|
|
public function broadcastAs(): string
|
|
{
|
|
return 'truck.load';
|
|
}
|
|
|
|
public function broadcastWith(): array
|
|
{
|
|
$trip = $this->trip;
|
|
$capacityKg = $trip->truck?->capacity_kg;
|
|
$currentLoad = $trip->current_load_kg ?? 0;
|
|
|
|
return [
|
|
'trip_id' => $trip->uuid,
|
|
'team_id' => $trip->team_id,
|
|
'truck_id' => $trip->truck?->uuid,
|
|
'current_load_kg' => $trip->current_load_kg,
|
|
'capacity_kg' => $capacityKg,
|
|
'is_full' => $capacityKg && $currentLoad >= $capacityKg,
|
|
'updated_at' => now()->toIso8601String(),
|
|
];
|
|
}
|
|
}
|