37 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			37 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| 
 | |
| namespace App\Http\Resources;
 | |
| 
 | |
| use Illuminate\Http\Resources\Json\JsonResource;
 | |
| use App\Http\Resources\SourceResource;
 | |
| use App\Http\Resources\TopicResource;
 | |
| use Mtownsend\ReadTime\ReadTime;
 | |
| 
 | |
| class ArticleResource extends JsonResource
 | |
| {
 | |
|     /**
 | |
|      * Transform the resource into an array.
 | |
|      *
 | |
|      * @param  \Illuminate\Http\Request  $request
 | |
|      * @return array
 | |
|      */
 | |
|     public function toArray($request)
 | |
|     {
 | |
|         return [
 | |
|             "id" => $this->id,
 | |
|             "title" => $this->title,
 | |
|             "author" => $this->author,
 | |
|             "meta" => $this->meta,
 | |
|             "featured_image" => $this->featured_image,
 | |
|             "url" => $this->url,
 | |
|             "body" => $this->body,
 | |
|             "readtime" => (new ReadTime($this->body))->get(),
 | |
|             "source" => new SourceResource($this->source),
 | |
|             "topics" => TopicResource::collection($this->topics),
 | |
|             "link" => url(route('api.article.show',$this->id)),
 | |
|             "published_date" => $this->published_date
 | |
|           
 | |
|         ];
 | |
|     }
 | |
| }
 |