5b68f4fa38
- Booking model with booking_vehicle_options line items (supports mixing vehicle options like front_seat + back_seat in one booking), price snapshot, status machine, and driver/car assignment fields - BookingService: front-seat max, disabled-option toggles, duplicate-option and whole-vehicle-exclusivity guards - CreateBookingAction, CancelBookingAction, AssignDriverAction - BookingRefGenerator: sequential EVB-AAAAA1-style refs via row lock - POST/GET/cancel booking API endpoints (Sanctum, ownership + admin policy) - BookingPlugin + Filament BookingResource: list, detail view, Cancel and Assign Driver actions (shared between table and detail page) - domain.md updated for multi-vehicle-option bookings (§2) and driver/ vehicle assignment (§5a)
60 lines
2.4 KiB
PHP
60 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace Modules\Booking\Http\Resources;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
class BookingResource extends JsonResource
|
|
{
|
|
/**
|
|
* Transform the resource into an array.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function toArray(Request $request): array
|
|
{
|
|
return [
|
|
'id' => $this->id,
|
|
'booking_ref' => $this->booking_ref,
|
|
'status' => $this->status,
|
|
'travel_date' => $this->travel_date?->toDateString(),
|
|
'is_round_trip' => $this->is_round_trip,
|
|
'return_travel_date' => $this->return_travel_date?->toDateString(),
|
|
'passenger_name' => $this->passenger_name,
|
|
'passenger_phone' => $this->passenger_phone,
|
|
'pickup_address' => $this->pickup_address,
|
|
'pickup_lat' => $this->pickup_lat,
|
|
'pickup_lng' => $this->pickup_lng,
|
|
'dropoff_address' => $this->dropoff_address,
|
|
'dropoff_lat' => $this->dropoff_lat,
|
|
'dropoff_lng' => $this->dropoff_lng,
|
|
'price' => $this->price,
|
|
'created_by_channel' => $this->created_by_channel,
|
|
// Only ever populated once status is confirmed — see AssignDriverAction.
|
|
'driver_name' => $this->driver_name,
|
|
'driver_phone' => $this->driver_phone,
|
|
'car_plate_number' => $this->car_plate_number,
|
|
'car_model' => $this->car_model,
|
|
'vehicle_options' => $this->whenLoaded('vehicleOptions', fn () => $this->vehicleOptions->map(fn ($selection) => [
|
|
'vehicle_option' => $selection->vehicle_option,
|
|
'passenger_count' => $selection->passenger_count,
|
|
'unit_price' => $selection->unit_price,
|
|
'line_total' => $selection->line_total,
|
|
])),
|
|
'route' => $this->whenLoaded('route', fn () => [
|
|
'id' => $this->route->id,
|
|
'ev_company_id' => $this->route->ev_company_id,
|
|
'from_destination_id' => $this->route->from_destination_id,
|
|
'to_destination_id' => $this->route->to_destination_id,
|
|
]),
|
|
'time_slot' => $this->whenLoaded('timeSlot', fn () => [
|
|
'id' => $this->timeSlot->id,
|
|
'label' => $this->timeSlot->label,
|
|
'time' => $this->timeSlot->time?->format('H:i'),
|
|
]),
|
|
'created_at' => $this->created_at,
|
|
];
|
|
}
|
|
}
|