Files
famous-ly4-ev/app-modules/booking/src/Http/Resources/BookingResource.php
T

60 lines
2.4 KiB
PHP
Raw Normal View History

<?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,
];
}
}