EscolaLMS/topic-types

View on GitHub
src/Http/Resources/TopicType/Admin/VideoResource.php

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
<?php

namespace EscolaLms\TopicTypes\Http\Resources\TopicType\Admin;

use EscolaLms\Auth\Traits\ResourceExtandable;
use EscolaLms\TopicTypes\Http\Resources\TopicType\Contacts\TopicTypeResourceContract;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Facades\Storage;

class VideoResource extends JsonResource implements TopicTypeResourceContract
{
    use ResourceExtandable;

    public function toArray($request)
    {
        $fields = [
            'id' => $this->id,
            'value' => $this->value,
            'url' => $this->value ? Storage::url($this->value) : null,
            'poster' => $this->poster,
            'poster_url' => $this->poster ? Storage::url($this->poster) : null,
            'width' => $this->width,
            'height' => $this->height,
            'length' => $this->length,
            'created_at' => $this->created_at,
            'updated_at' => $this->updated_at,
        ];

        return self::apply($fields, $this);
    }
}