-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create some resource to get data for blog posts
- Loading branch information
Showing
3 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace CSlant\Blog\Api\Http\Resources; | ||
|
||
use Botble\Blog\Models\Category; | ||
use CSlant\Blog\Core\Models\User; | ||
use Illuminate\Http\Resources\Json\JsonResource; | ||
|
||
/** | ||
* @mixin Category | ||
*/ | ||
class AuthorResource extends JsonResource | ||
{ | ||
/** */ | ||
public function toArray($request): array | ||
{ | ||
/** @var User $this */ | ||
return [ | ||
'id' => $this->id, | ||
'first_name' => $this->first_name, | ||
'last_name' => $this->last_name, | ||
'image' => $this->avatar_url, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace CSlant\Blog\Api\Http\Resources; | ||
|
||
use Botble\Blog\Models\Category; | ||
use Illuminate\Http\Resources\Json\JsonResource; | ||
|
||
/** | ||
* @mixin Category | ||
*/ | ||
class CategoryResource extends JsonResource | ||
{ | ||
/** */ | ||
public function toArray($request): array | ||
{ | ||
/** @var Category $this */ | ||
return [ | ||
'id' => $this->id, | ||
'name' => $this->name, | ||
'slug' => $this->slug, | ||
'url' => $this->url, | ||
'description' => $this->description, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace CSlant\Blog\Api\Http\Resources; | ||
|
||
use Botble\Blog\Http\Resources\TagResource; | ||
use Botble\Blog\Models\Post; | ||
use Botble\Media\Facades\RvMedia; | ||
use Botble\Blog\Http\Resources\ListPostResource as BaseListPostResource; | ||
|
||
/** | ||
* @mixin Post | ||
*/ | ||
class ListPostResource extends BaseListPostResource | ||
{ | ||
public function toArray($request): array | ||
{ | ||
/** @var Post $this */ | ||
return [ | ||
'id' => $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, | ||
]; | ||
} | ||
} |