From 789bd7c52aff74831bf53e9a59949c1f053d59e1 Mon Sep 17 00:00:00 2001 From: Tan Nguyen Date: Thu, 5 Dec 2024 16:45:27 +0700 Subject: [PATCH] feat: create some resource to get data for blog posts --- src/Http/Resources/AuthorResource.php | 25 ++++++++++++++++++++ src/Http/Resources/CategoryResource.php | 25 ++++++++++++++++++++ src/Http/Resources/ListPostResource.php | 31 +++++++++++++++++++++++++ 3 files changed, 81 insertions(+) create mode 100644 src/Http/Resources/AuthorResource.php create mode 100644 src/Http/Resources/CategoryResource.php create mode 100644 src/Http/Resources/ListPostResource.php diff --git a/src/Http/Resources/AuthorResource.php b/src/Http/Resources/AuthorResource.php new file mode 100644 index 0000000..526d242 --- /dev/null +++ b/src/Http/Resources/AuthorResource.php @@ -0,0 +1,25 @@ + $this->id, + 'first_name' => $this->first_name, + 'last_name' => $this->last_name, + 'image' => $this->avatar_url, + ]; + } +} diff --git a/src/Http/Resources/CategoryResource.php b/src/Http/Resources/CategoryResource.php new file mode 100644 index 0000000..1597cee --- /dev/null +++ b/src/Http/Resources/CategoryResource.php @@ -0,0 +1,25 @@ + $this->id, + 'name' => $this->name, + 'slug' => $this->slug, + 'url' => $this->url, + 'description' => $this->description, + ]; + } +} diff --git a/src/Http/Resources/ListPostResource.php b/src/Http/Resources/ListPostResource.php new file mode 100644 index 0000000..0dfd65b --- /dev/null +++ b/src/Http/Resources/ListPostResource.php @@ -0,0 +1,31 @@ + $this->id, + 'name' => $this->name, + 'slug' => $this->slug, + 'description' => $this->description, + 'image' => $this->image ? RvMedia::url($this->image) : null, + 'categories' => CategoryResource::collection($this->categories), + 'tags' => TagResource::collection($this->tags), + 'author' => AuthorResource::make($this->author), + 'created_at' => $this->created_at, + 'updated_at' => $this->updated_at, + ]; + } +}