Files
wiki_travel_site/app/Http/Resources/AttractionResource.php
T

31 lines
847 B
PHP
Raw Normal View History

2026-04-28 16:10:27 +03:00
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class AttractionResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'name' => $this->name,
'description' => $this->description,
'latitude' => (float) $this->latitude,
'longitude' => (float) $this->longitude,
'category' => $this->category,
'source' => $this->source,
'rating' => $this->rating ? (float) $this->rating : null,
'image_url' => $this->image_url,
'city' => new CityResource($this->whenLoaded('city')),
];
}
}