%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /var/www/html/diaspora/api/app/Transformers/App/
Upload File :
Create Path :
Current File : /var/www/html/diaspora/api/app/Transformers/App/PostListTransformer.php

<?php

namespace App\Transformers\App;

use App\Models\Post;
use App\Transformers\BaseTransformer;
use App\Transformers\CategoryTransformer;

class PostListTransformer extends BaseTransformer
{
    protected $defaultIncludes = [
        '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 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,
            'short_desc'     => $post->short_desc
                ?: '',
            'featured_image' => $post->getFeaturedImage(),
            'created_at'     => $post->published_at,
            'updated_at'     => $post->published_at,
            'published_at'   => $post->published_at,
        ];
    }
}

Zerion Mini Shell 1.0