阶段更新
This commit is contained in:
36
modules/Cms/Http/Resources/ArticleResource.php
Normal file
36
modules/Cms/Http/Resources/ArticleResource.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Cms\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Jason\Api\Api;
|
||||
|
||||
class ArticleResource extends JsonResource
|
||||
{
|
||||
|
||||
public function toArray($request): array
|
||||
{
|
||||
$user = Api::user();
|
||||
|
||||
return [
|
||||
'article_id' => $this->id,
|
||||
'title' => $this->title,
|
||||
// 'sub_title' => $this->sub_title,
|
||||
'description' => $this->description,
|
||||
// 'slug' => $this->slug,
|
||||
'categories' => CategoryBaseResource::collection($this->categories),
|
||||
'tags' => TagResource::collection($this->tags),
|
||||
'cover' => $this->cover_url,
|
||||
'pictures' => $this->pictures_url,
|
||||
'clicks' => $this->clicks,
|
||||
'favorites' => $this->favorites()->count(),
|
||||
'subscribes' => $this->subscribers()->count(),
|
||||
'isFavorite' => $user && $this->isFavoritedBy($user),
|
||||
'isSubscribed' => $user && $this->isSubscribedBy($user),
|
||||
'content' => $this->content,
|
||||
'attachments' => $this->attachments,
|
||||
'created_at' => (string) $this->created_at,
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user