Files
memefast/app/Models/Video.php
2025-05-28 12:59:01 +08:00

81 lines
1.6 KiB
PHP

<?php
/**
* Created by Reliese Model.
*/
namespace App\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Str;
/**
* Class Video
*
* @property int $id
* @property string|null $external_id
* @property Carbon|null $created_at
* @property Carbon|null $updated_at
* @property Collection|VideoRender[] $video_renders
*/
class Video extends Model
{
use SoftDeletes;
protected $table = 'videos';
protected $casts = [
'width' => 'int',
'height' => 'int',
'payload' => 'object',
'render_settings' => 'object',
];
protected $fillable = [
'external_id',
'content_type',
'width',
'height',
'aspect_ratio',
'payload',
'render_settings',
];
protected $hidden = [
'id',
];
public function video_renders()
{
return $this->hasMany(VideoRender::class)->orderBy('id', 'DESC');
}
public function video_captions()
{
return $this->hasMany(VideoCaption::class)->orderBy('time', 'ASC');
}
public function video_elements()
{
return $this->hasMany(VideoElement::class)->orderBy('time', 'ASC');
}
public function latest_render()
{
return $this->hasOne(VideoRender::class)->latest();
}
/**
* The "booted" method of the model.
*/
protected static function booted(): void
{
static::creating(function ($model) {
$model->uuid = $model->uuid ?? (string) Str::uuid();
});
}
}