<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;

class PageResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        return [
            'id' => $this->id,
            'title' => $this->title,
            'subtitle' => $this->subtitle,
            'published_at' => $this->updated_at->toDateTimeString(),
            'created_at' => $this->updated_at->toDateTimeString(),
            'updated_at' => $this->created_at->toDateTimeString(),
            'slug' => $this->slug,
            'components' =>  $this->whenLoaded('components'),
        ];
    }
}
