34 lines
1.0 KiB
PHP
34 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
class PostResource extends JsonResource
|
|
{
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function toArray(Request $request): array
|
|
{
|
|
return [
|
|
'id' => $this->id,
|
|
'title' => $this->title,
|
|
'slug' => $this->slug,
|
|
'excerpt' => $this->excerpt,
|
|
'body' => $this->body,
|
|
'featured_image' => $this->featured_image,
|
|
'status' => $this->status,
|
|
'published_at' => $this->published_at,
|
|
'meta_title' => $this->meta_title,
|
|
'meta_description' => $this->meta_description,
|
|
'author' => new UserResource($this->whenLoaded('user')),
|
|
'category' => new CategoryResource($this->whenLoaded('category')),
|
|
'tags' => TagResource::collection($this->whenLoaded('tags')),
|
|
'created_at' => $this->created_at,
|
|
'updated_at' => $this->updated_at,
|
|
];
|
|
}
|
|
}
|