AdminMakeVideo.php 1.27 KB
<?php

namespace App\Models;

use Dcat\Admin\Traits\HasDateTimeFormatter;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;

class AdminMakeVideo extends Model
{
	use HasDateTimeFormatter;
    protected $table = 'admin_make_video';

    protected $guarded = [''];

    public function getVideoUrl()
    {
        if (Str::contains($this->video_url, '//')) {
            return $this->video_url;
        }

        return Storage::disk('public')->url($this->video_url);
    }

    public function getThumbnailUrl()
    {
        if (Str::contains($this->thumbnail_url, '//')) {
            return $this->thumbnail_url;
        }

        return Storage::disk('public')->url($this->thumbnail_url);
    }

    public function poem()
    {
        return $this->hasOne(OnePoem::class,'id','poem_id');
    }

    public function poem2()
    {
        return $this->hasOne(OnePoem2::class,'id','poem_id');
    }

    public function temp()
    {
        return $this->hasOne(VideoTemp::class,'id','temp_id');
    }

    public function getContentPosition($field = 'one_poem')
    {
        $component  = $this->temp()->first()->components()->where('name','=',$field)->first();

        return VideoTemp::POSITION_FFMPEG[$component->position];
    }
}