34 lines
901 B
PHP
34 lines
901 B
PHP
<?php
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
use Storage;
|
|
|
|
class ExplainResource extends JsonResource
|
|
{
|
|
|
|
/**
|
|
* Transform the resource into an array.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return array
|
|
*/
|
|
public function toArray($request)
|
|
{
|
|
$user = \Auth::guard('api')->user();
|
|
return [
|
|
'id' => $this->id,
|
|
'title' => $this->title,
|
|
'description' => $this->description,
|
|
'cover' => Storage::disk(config('admin.upload.disk'))->url($this->cover),
|
|
'content' => $this->content,
|
|
'clicks' => $this->clicks,
|
|
'canRead' => $this->canRead(),
|
|
'created_at' => $this->created_at->format('Y年m月d日'),
|
|
'isFavorited' => $this->isFavoritedBy($user),
|
|
];
|
|
}
|
|
|
|
}
|