Files
portal-api/app/Http/Resources/Api/PostResource.php
baodev0 520f21cb11 feat: add GeneratesUniqueSlug class for unique slug generation
feat: create PostCategoryFactory for generating post category data

feat: create PostFactory for generating post data

feat: add retry_requested_at column to services table

feat: add vcenter provisioning fields to products table

feat: add module_host_id to os table

feat: create email_notification_templates table for email templates

feat: add scenario and format fields to template table

feat: add admin fields to transactions table

fix: update ticket table columns and types

feat: add uuid to ticket table and backfill existing records

fix: make ticket_reply user_id nullable

feat: create notifications table for user notifications

fix: make ticket uuid nullable

feat: create post_categories table for blog categories

feat: create posts table for blog posts

feat: add invoice email template for PDF generation
2026-05-25 15:39:42 +07:00

49 lines
2.0 KiB
PHP

<?php
namespace App\Http\Resources\Api;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class PostResource extends JsonResource
{
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'post_category_id' => $this->post_category_id,
'title' => $this->title,
'slug' => $this->slug,
'excerpt' => $this->excerpt,
'content' => $this->content,
'thumbnail' => $this->thumbnail,
'status' => $this->status,
'is_featured' => (bool) $this->is_featured,
'view_count' => (int) $this->view_count,
'reading_time' => $this->reading_time,
'meta_title' => $this->meta_title,
'meta_description' => $this->meta_description,
'published_at' => $this->published_at?->toISOString(),
'created_at' => $this->created_at?->toISOString(),
'updated_at' => $this->updated_at?->toISOString(),
'category' => $this->whenLoaded('category', fn () => new PostCategoryResource($this->category)),
'related_posts' => $this->when(isset($this->related_posts), fn () => $this->related_posts->map(fn ($post) => [
'id' => $post->id,
'post_category_id' => $post->post_category_id,
'title' => $post->title,
'slug' => $post->slug,
'excerpt' => $post->excerpt,
'thumbnail' => $post->thumbnail,
'status' => $post->status,
'is_featured' => (bool) $post->is_featured,
'view_count' => (int) $post->view_count,
'reading_time' => $post->reading_time,
'published_at' => $post->published_at?->toISOString(),
'category' => $post->relationLoaded('category') && $post->category
? new PostCategoryResource($post->category)
: null,
])->values()),
];
}
}