84 lines
1.9 KiB
PHP
84 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
/**
|
|
* @property int $id
|
|
* @property int $order
|
|
* @property string $link
|
|
* @property string $video_link
|
|
* @property integer $video_size
|
|
* @property string $title
|
|
* @property string $duration
|
|
* @property integer $course_id
|
|
* @property bool $sync_offline
|
|
* @property string $video_path
|
|
* @property string $directory_path
|
|
* @property Course $course
|
|
*/
|
|
class Chapter extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $fillable = [
|
|
'order',
|
|
'link',
|
|
'video_link',
|
|
'video_size',
|
|
'title',
|
|
'duration',
|
|
'course_id',
|
|
'sync_offline',
|
|
];
|
|
|
|
protected $appends = ['video_path', 'directory_path', 'video_url'];
|
|
|
|
public function course(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Course::class);
|
|
}
|
|
|
|
protected function videoUrl(): Attribute
|
|
{
|
|
return Attribute::make(
|
|
get: fn() => url($this->course_id . '/' . $this->order . '.mp4')
|
|
);
|
|
}
|
|
|
|
protected function videoPath(): Attribute
|
|
{
|
|
return Attribute::make(
|
|
get: fn() => $this->directory_path . '/' . $this->order . '.mp4'
|
|
);
|
|
}
|
|
|
|
protected function directoryPath(): Attribute
|
|
{
|
|
return Attribute::make(
|
|
get: fn() => public_path($this->course_id)
|
|
);
|
|
}
|
|
|
|
protected function isVideoFile(): Attribute
|
|
{
|
|
return Attribute::make(
|
|
get: fn() => is_file($this->video_path)
|
|
);
|
|
}
|
|
|
|
public function videoSizeHuman(): Attribute
|
|
{
|
|
return Attribute::make(
|
|
get: function () {
|
|
return formatFileSize($this->video_size);
|
|
},
|
|
);
|
|
}
|
|
|
|
}
|