parsaaghayi-backend/app/Http/Resources/PostResource.php
2024-10-13 20:16:08 +03:30

36 lines
1.1 KiB
PHP

<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use Carbon\Carbon;
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,
'excerpt' => $this->excerpt,
'body' => $this->body,
'author' => new UserResource($this->author),
'category' => new CategoryResource($this->category),
'tags' => TagResource::collection($this->tags),
'featured_image' => $this->featured_image,
'views' => $this->views,
'likes' => $this->likes,
'published_at' => $this->published_at,
'created_at' => Carbon::parse($this->created_at)->format('M d Y'),
'updated_at' => Carbon::parse($this->updated_at)->format('M d Y'),
];
}
}