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

44 lines
1.9 KiB
PHP

<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class HouseholdResource extends JsonResource
{
public function toArray(Request $request): array
{
return [
'id' => $this->uuid,
'address_line' => $this->address_line,
'household_size' => $this->household_size,
'barangay_id' => $this->barangay_id,
'assigned_drop_off_point_id' => $this->assigned_drop_off_point_id,
'coordinates' => $this->coordinates ? [
'lat' => $this->coordinates->latitude,
'lng' => $this->coordinates->longitude,
] : null,
'barangay' => BarangayResource::make($this->whenLoaded('barangay')),
'service_area' => $this->barangay?->serviceAreas->first()?->name ?? 'None',
'head' => UserResource::make($this->whenLoaded('head')),
'verification_status' => $this->verification_status,
'verified_at' => $this->verified_at?->toIso8601String(),
'rejection_reason' => $this->rejection_reason,
'proof_of_residency_uploaded' => (bool) $this->proof_of_residency_path,
'proof_url' => $this->proof_of_residency_path
? route('api.v1.admin.households.proof', $this->uuid)
: null,
'assigned_drop_off_point' => DropOffPointResource::make($this->whenLoaded('assignedDropOffPoint')),
'members' => HouseholdMemberResource::collection($this->whenLoaded('members')),
'member_count' => $this->whenCounted('members'),
'created_at' => $this->created_at?->toIso8601String(),
'updated_at' => $this->updated_at?->toIso8601String(),
'tenant' => $this->whenLoaded('tenant', fn () => [
'id' => $this->tenant->id,
'name' => $this->tenant->name,
]),
];
}
}