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

38 lines
1.2 KiB
PHP

<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class ServiceAreaResource extends JsonResource
{
public function toArray(Request $request): array
{
$boundaryPoints = null;
if ($this->boundary) {
$rings = $this->boundary->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,
'status' => $this->status,
'description' => $this->description,
'boundary' => $boundaryPoints,
'barangay_count' => $this->whenCounted('barangays'),
'barangays' => BarangayResource::collection($this->whenLoaded('barangays')),
'created_at' => $this->created_at?->toIso8601String(),
'updated_at' => $this->updated_at?->toIso8601String(),
];
}
}