%PDF- %PDF-
Direktori : /var/www/html/news/app/Transformers/ |
Current File : /var/www/html/news/app/Transformers/ArticleTransformer.php |
<?php namespace App\Transformers; use App\Models\Article; class ArticleTransformer extends BaseTransformer { protected $availableIncludes = [ 'category', 'creator', 'lastModifier', 'tags', 'comments' ]; public function transform(Article $article) { $data = $this->transformColumns($article); return $data; } protected function getTransformableColumns() { return [ 'id' => 'id', 'title' => 'title', 'description' => 'description', 'content' => 'content', 'number_of_views' => 'number_of_views', 'creator_id' => 'creator_id', 'last_modifier_id' => 'last_modifier_id', 'category_id' => 'category_id', 'created_at' => 'created_at', 'updated_at' => 'updated_at', 'is_featured' => 'is_featured' ]; } public function includeCategory(Article $article) { if (!empty($article->category)) { return $this->item($article->category, new CategoryTransformer, 'category'); } return null; } public function includeCreator(Article $article) { if (!empty($article->creator)) { return $this->item($article->creator, new UserTransformer, 'creator'); } return null; } public function includeLastModifier(Article $article) { if (!empty($article->lastModifier)) { return $this->item($article->lastModifier, new UserTransformer, 'lastModifier'); } return null; } public function includeTags(Article $article) { if (!empty($article->tags)) { return $this->collection($article->tags, new TagTransformer, 'tags'); } } public function includeComments(Article $article) { if (!empty($article->comments)) { $comments = $article->comments; return $this->collection($comments, new CommentTransformer, 'comments'); } } }