2025-12-01 17:02:01 +03:00

76 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\HasMany;
class Deceased extends Model
{
use HasFactory;
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'deceased';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'last_name',
'first_name',
'birth_date',
'death_date',
'place_of_death',
'notes'
];
/**
* The attributes that should be cast.
*
* @var array
*/
protected $casts = [
'birth_date' => 'date',
'death_date' => 'date',
];
/**
* Get the documents associated with the deceased.
*/
public function documents(): HasMany
{
return $this->hasMany(DeceasedDocument::class);
}
/**
* Get the interventions associated with the deceased.
*/
public function interventions(): HasMany
{
return $this->hasMany(Intervention::class);
}
/**
* Get the file attachments for the deceased (polymorphic).
*/
public function fileAttachments()
{
return $this->morphMany(FileAttachment::class, 'attachable')->orderBy('sort_order');
}
/**
* Get the files attached to this deceased.
*/
public function attachedFiles()
{
return $this->fileAttachments()->with('file');
}
}