88 lines
2.0 KiB
PHP
88 lines
2.0 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 bool $is_complete
|
|
* @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',
|
|
'is_complete',
|
|
];
|
|
|
|
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(
|
|
'videos' . DIRECTORY_SEPARATOR . $this->course_id . DIRECTORY_SEPARATOR . $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('videos' . DIRECTORY_SEPARATOR . $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);
|
|
},
|
|
);
|
|
}
|
|
|
|
}
|