2025-11-11 17:45:58 +03:00

100 lines
2.2 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\Database\Eloquent\Relations\HasMany;
class Intervention extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'client_id',
'deceased_id',
'order_giver',
'location_id',
'type',
'scheduled_at',
'duration_min',
'status',
'assigned_practitioner_id',
'attachments_count',
'notes',
'created_by'
];
/**
* The attributes that should be cast.
*
* @var array
*/
protected $casts = [
'scheduled_at' => 'datetime',
'attachments_count' => 'integer'
];
/**
* Get the client associated with the intervention.
*/
public function client(): BelongsTo
{
return $this->belongsTo(Client::class);
}
/**
* Get the deceased associated with the intervention.
*/
public function deceased(): BelongsTo
{
return $this->belongsTo(Deceased::class);
}
/**
* Get the location associated with the intervention.
*/
public function location(): BelongsTo
{
return $this->belongsTo(ClientLocation::class);
}
/**
* Get the practitioner assigned to the intervention.
*/
public function assignedPractitioner(): BelongsTo
{
return $this->belongsTo(Thanatopractitioner::class, 'assigned_practitioner_id');
}
/**
* Get the user who created the intervention.
*/
public function creator(): BelongsTo
{
return $this->belongsTo(User::class, 'created_by');
}
/**
* Get the attachments for the intervention.
*/
public function attachments(): HasMany
{
return $this->hasMany(InterventionAttachment::class);
}
/**
* Get the notifications for the intervention.
*/
public function notifications(): HasMany
{
return $this->hasMany(InterventionNotification::class);
}
}