Files
shopit-back/app/Domains/Attachable/Models/Attachment.php

50 lines
999 B
PHP

<?php
namespace App\Domains\Attachable\Models;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphTo;
use Illuminate\Support\Str;
#[Fillable([
'attachable_type',
'attachable_id',
'path',
'filename',
'type',
'mime_type',
'extension',
'size',
])]
class Attachment extends Model
{
use HasFactory;
protected $table = 'attachments';
protected static function booted(): void
{
static::creating(function (self $attachment): void {
$attachment->key = (string) Str::uuid();
});
}
protected function casts(): array
{
return [
'attachable_id' => 'integer',
'size' => 'integer',
];
}
/**
* @return MorphTo<Model, $this>
*/
public function attachable(): MorphTo
{
return $this->morphTo();
}
}