%PDF- %PDF-
Direktori : /var/www/html/shaban/duassis/api/app/Transformers/ |
Current File : //var/www/html/shaban/duassis/api/app/Transformers/PostTransformer.php |
<?php namespace App\Transformers; use App\Models\Post; class PostTransformer extends BaseTransformer { protected $defaultIncludes = [ 'author', ]; protected $availableIncludes = [ 'field', 'category', ]; public function includeAuthor(Post $post) { return $this->item($post->author, new LightUserTransformer(), 'user'); } public function includeCategory(Post $post) { return $this->item($post->category, new CategoryTransformer(), 'category'); } public function includeField(Post $post) { if ($field = $post->field) { return $this->item($post->field, new FieldTransformer(), 'field'); } return null; } /** * @param Post $post * * @return array */ public function transform(Post $post) { return [ 'id' => $post->id, 'title' => $post->title, 'type' => $post->type, 'expires_at' => $post->expires_at, 'created_at' => $post->created_at, ]; } }