%PDF- %PDF-
Direktori : /var/www/html/diaspora/api/app/Transformers/App/ |
Current File : /var/www/html/diaspora/api/app/Transformers/App/PostDetailsTransformer.php |
<?php namespace App\Transformers\App; use App\Models\Post; use App\Transformers\BaseTransformer; use App\Transformers\CategoryTransformer; use App\Transformers\MediaTransformer; class PostDetailsTransformer extends BaseTransformer { protected $defaultIncludes = [ 'media', 'country', 'category', 'categories', ]; public function includeCountry(Post $post) { return $this->item($post->country, new CountryTransformer, 'country'); } public function includeCategory(Post $post) { return $this->item($post->category, new CategoryTransformer, 'category'); } public function includeMedia(Post $post) { return $this->collection($post->getCarouselImages(), new MediaTransformer, 'media'); } public function includeCategories(Post $post) { return $this->collection($post->categories, new CategoryTransformer, 'categories'); } /** * @param Post $post * * @return array */ public function transform(Post $post) { return [ 'id' => $post->id, 'title' => $post->title, 'content' => $this->injectStyles() . $post->content . $this->injectScripts(), 'featured_image' => $post->getFeaturedImage(), 'video_url' => $post->video_url, 'video_type' => $post->video_type ?: '', 'created_at' => $post->published_at, 'updated_at' => $post->published_at, 'published_at' => $post->published_at, ]; } }