New-Thanasoft/thanasoft-back/app/Http/Resources/Client/ClientLocationResource.php
2025-10-09 18:25:02 +03:00

52 lines
1.8 KiB
PHP

<?php
namespace App\Http\Resources\Client;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class ClientLocationResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'client_id' => $this->client_id,
'name' => $this->name,
'address' => [
'line1' => $this->address_line1,
'line2' => $this->address_line2,
'postal_code' => $this->postal_code,
'city' => $this->city,
'country_code' => $this->country_code,
'full_address' => $this->full_address,
],
'gps_coordinates' => $this->gps_coordinates,
'gps_lat' => $this->gps_lat,
'gps_lng' => $this->gps_lng,
'is_default' => $this->is_default,
'created_at' => $this->created_at?->format('Y-m-d H:i:s'),
'updated_at' => $this->updated_at?->format('Y-m-d H:i:s'),
// Relations
'client' => new ClientResource($this->whenLoaded('client')),
//'interventions_as_origin' => InterventionResource::collection($this->whenLoaded('interventionsAsOrigin')),
//'transports_as_origin' => TransportResource::collection($this->whenLoaded('transportsAsOrigin')),
//'transports_as_destination' => TransportResource::collection($this->whenLoaded('transportsAsDestination')),
];
}
public function with(Request $request): array
{
return [
'status' => 'success',
'message' => 'Lieu client récupéré avec succès',
];
}
}