Files
wiki_travel_site/app/Http/Resources/CityResource.php
T
2026-04-28 16:10:27 +03:00

33 lines
1009 B
PHP

<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class CityResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'slug' => $this->slug,
'name' => $this->name,
'country' => $this->country,
'latitude' => (float) $this->latitude,
'longitude' => (float) $this->longitude,
'wikipedia_summary' => $this->wikipedia_summary,
'wikipedia_url' => $this->wikipedia_url,
'attractions_count' => $this->whenCounted('attractions'),
'attractions' => AttractionResource::collection($this->whenLoaded('attractions')),
'created_at' => $this->created_at?->toISOString(),
'updated_at' => $this->updated_at?->toISOString(),
];
}
}