%PDF- %PDF-
Direktori : /var/www/html/news/app/Transformers/ |
Current File : /var/www/html/news/app/Transformers/CategoryTransformer.php |
<?php namespace App\Transformers; use App\Models\Category; class CategoryTransformer extends BaseTransformer { protected $availableIncludes = [ 'parent', 'children', 'articles' ]; public function transform(Category $category) { $data = $this->transformColumns($category); return $data; } public function includeParent(Category $category) { if ($category->parent) { return $this->item($category->parent, new CategoryTransformer, 'parent'); } return null; } public function includeChildren(Category $category) { if ($category->children) { return $this->collection($category->children, new CategoryTransformer, 'children'); } return null; } public function includeArticles(Category $category) { if (!empty($category->articles)) { return $this->collection($category->articles, new ArticleTransformer, 'articles'); } } protected function getTransformableColumns() { return [ 'id' => 'id', 'name' => 'name', 'description' => 'description', 'parent_id' => 'parent_id', 'created_at' => 'created_at', 'updated_at' => 'updated_at' ]; } }