33 lines
965 B
PHP
33 lines
965 B
PHP
<?php
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
class PostResource extends JsonResource
|
|
{
|
|
/**
|
|
* Transform the resource into an array.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function toArray(Request $request): array
|
|
{
|
|
return [
|
|
'id' => $this->id,
|
|
'title' => $this->title,
|
|
'slug' => $this->slug,
|
|
'content' => $this->content,
|
|
'excerpt' => $this->excerpt,
|
|
'featured_image' => $this->featured_image,
|
|
'is_featured' => (bool) $this->is_featured,
|
|
'status' => $this->status,
|
|
'published_at' => $this->published_at?->toISOString(),
|
|
'category' => new CategoryResource($this->whenLoaded('category')),
|
|
'created_at' => $this->created_at?->toISOString(),
|
|
'updated_at' => $this->updated_at?->toISOString(),
|
|
];
|
|
}
|
|
}
|