33 lines
969 B
PHP
33 lines
969 B
PHP
<?php
|
|
|
|
namespace App\Endpoint\Api\Http\Resources;
|
|
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
class ArticleSimpleResource extends JsonResource
|
|
{
|
|
/**
|
|
* Transform the resource into an array.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
|
|
*/
|
|
public function toArray($request)
|
|
{
|
|
return [
|
|
'id' => $this->id,
|
|
'title' => $this->title,
|
|
'subtitle' => $this->subtitle,
|
|
'cover' => $this->cover,
|
|
'points'=> $this->points,
|
|
'likes' => $this->likes,
|
|
'like_status' => $this->whenLoaded('likesInfo', function () {
|
|
return $this->likesInfo->count() > 0;
|
|
}, false),
|
|
'jump_type' => $this->jump_type,
|
|
'jump_link' => (string) $this->jump_link,
|
|
'created_at' => $this->created_at->toDateTimeString(),
|
|
];
|
|
}
|
|
}
|