summaryrefslogtreecommitdiff
path: root/app/Rugby/Model/Video.php
blob: 2182b652f4dfa1f8fce08907ff57e972474d02e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php

namespace App\Rugby\Model;

use App\Rugby\Model\Match;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Storage;

class Video extends Model
{
    protected $table = 'videos';
    protected $casts = ['date' => 'datetime:Y-m-d'];
    protected $fillable = ['path'];

    public function match()
    {
        return $this->belongsTo(Match::class);
    }

    public function getFilename(): string
    {
        $parts = explode('/', $this->path);

        return $parts[count($parts) - 1];
    }

    public function getUrl(): string
    {
        return asset('storage/matches/' . $this->getFilename());
        // return Storage::disk('local')->url(
        //     'matches/' . $this->getFilename()
        // );
    }
}