New-Thanasoft/thanasoft-back/app/Models/InterventionPractitioner.php
2025-11-26 17:53:17 +03:00

73 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;
class InterventionPractitioner extends Model
{
use HasFactory;
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'intervention_practitioner';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'intervention_id',
'practitioner_id',
'role',
'assigned_at'
];
/**
* The attributes that should be cast.
*
* @var array
*/
protected $casts = [
'assigned_at' => 'datetime'
];
/**
* Get the intervention that owns the practitioner assignment.
*/
public function intervention(): BelongsTo
{
return $this->belongsTo(Intervention::class);
}
/**
* Get the practitioner assigned to the intervention.
*/
public function practitioner(): BelongsTo
{
return $this->belongsTo(Thanatopractitioner::class, 'practitioner_id');
}
/**
* Scope to get principal practitioners.
*/
public function scopePrincipal($query)
{
return $query->where('role', 'principal');
}
/**
* Scope to get assistant practitioners.
*/
public function scopeAssistant($query)
{
return $query->where('role', 'assistant');
}
}