45 lines
949 B
PHP
45 lines
949 B
PHP
<?php
|
|
|
|
namespace App\Domains\Attachable\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
|
|
|
#[Fillable([
|
|
'attachable_type',
|
|
'attachable_id',
|
|
'attachment_id',
|
|
])]
|
|
class AttachableAttachment extends Model
|
|
{
|
|
protected $table = 'attachable_attachments';
|
|
|
|
public $timestamps = false;
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'attachable_id' => 'integer',
|
|
'attachment_id' => 'integer',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return MorphTo<Model, $this>
|
|
*/
|
|
public function attachable(): MorphTo
|
|
{
|
|
return $this->morphTo();
|
|
}
|
|
|
|
/**
|
|
* @return BelongsTo<Attachment, $this>
|
|
*/
|
|
public function attachment(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Attachment::class, 'attachment_id');
|
|
}
|
|
}
|