Files
water-back/modules/Cms/Http/Resources/ArticleResource.php
2023-01-12 14:47:38 +08:00

36 lines
1.2 KiB
PHP

<?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,
];
}
}