*/ protected $fillable = [ 'employee_id', 'diploma_number', 'diploma_date', 'authorization_number', 'authorization_issue_date', 'authorization_expiry_date', 'notes', ]; /** * The attributes that should be cast. * * @var array */ protected $casts = [ 'diploma_date' => 'date', 'authorization_issue_date' => 'date', 'authorization_expiry_date' => 'date', 'created_at' => 'datetime', 'updated_at' => 'datetime', ]; /** * Get the employee that owns the thanatopractitioner. */ public function employee(): BelongsTo { return $this->belongsTo(Employee::class); } /** * Get all documents associated with the thanatopractitioner. */ public function documents(): HasMany { return $this->hasMany(PractitionerDocument::class, 'practitioner_id'); } /** * Scope a query to only include practitioners with valid authorization. */ public function scopeWithValidAuthorization($query) { return $query->where('authorization_expiry_date', '>=', now()); } /** * Scope a query to only include practitioners with expired authorization. */ public function scopeWithExpiredAuthorization($query) { return $query->where('authorization_expiry_date', '<', now()); } /** * Check if the authorization is still valid. */ public function getIsAuthorizationValidAttribute(): bool { if (!$this->authorization_expiry_date) { return false; } return $this->authorization_expiry_date >= now(); } }