thats-me/backend/app/Models/EventMedia.php

66 lines
1.5 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Str;
class EventMedia extends Model
{
/** @use HasFactory<\Database\Factories\EventMediaFactory> */
use HasFactory;
protected $fillable = [
'uuid',
'user_id',
'event_id',
'collection',
'name',
'mime_type',
'disk',
'path',
'thumbnail_path',
'preview_path',
'size',
'width',
'height',
'thumbnail_width',
'thumbnail_height',
'preview_width',
'preview_height',
];
protected function casts(): array
{
return [
'size' => 'integer',
'width' => 'integer',
'height' => 'integer',
'thumbnail_width' => 'integer',
'thumbnail_height' => 'integer',
'preview_width' => 'integer',
'preview_height' => 'integer',
];
}
protected static function booted(): void
{
static::creating(function (EventMedia $media): void {
if (! $media->uuid) {
$media->uuid = (string) Str::uuid();
}
});
}
public function event(): BelongsTo
{
return $this->belongsTo(Event::class);
}
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
}