Files
Verde-Web/app/Http/Resources/DumpsiteResource.php

50 lines
1.8 KiB
PHP

<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class DumpsiteResource extends JsonResource
{
public function toArray(Request $request): array
{
$boundaryPoints = null;
if ($this->boundary_polygon) {
$rings = $this->boundary_polygon->getGeometries();
$ring = $rings->first();
if ($ring) {
$boundaryPoints = $ring->getGeometries()
->map(fn ($p) => ['lat' => $p->latitude, 'lng' => $p->longitude])
->all();
}
}
return [
'id' => $this->uuid,
'db_id' => $this->id,
'name' => $this->name,
'code' => $this->code,
'address_line' => $this->address_line,
'coordinates' => $this->coordinates ? [
'lat' => $this->coordinates->latitude,
'lng' => $this->coordinates->longitude,
] : null,
'boundary_polygon' => $boundaryPoints,
'accepted_waste_types' => $this->accepted_waste_types,
'operating_hours' => $this->operating_hours,
'capacity_tons' => $this->capacity_tons,
'permit_number' => $this->permit_number,
'status' => $this->status,
'contact_person' => $this->contact_person,
'contact_phone' => $this->contact_phone,
'city_municipality' => CityMunicipalityResource::make($this->whenLoaded('cityMunicipality')),
'tenant' => $this->whenLoaded('tenant', fn () => [
'id' => $this->tenant->id,
'name' => $this->tenant->name,
]),
'created_at' => $this->created_at?->toIso8601String(),
];
}
}