60 lines
1.5 KiB
PHP
60 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Database\Factories\DepartmentFactory;
|
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
#[Fillable(['name', 'is_active', 'department_profile_id'])]
|
|
class Department extends Model
|
|
{
|
|
/** @use HasFactory<DepartmentFactory> */
|
|
use HasFactory;
|
|
|
|
/**
|
|
* Get the profile that the department belongs to.
|
|
*
|
|
* @return BelongsTo<DepartmentProfile, $this>
|
|
*/
|
|
public function departmentProfile(): BelongsTo
|
|
{
|
|
return $this->belongsTo(DepartmentProfile::class);
|
|
}
|
|
|
|
/**
|
|
* Get the services provided by the department.
|
|
*
|
|
* @return HasMany<ServiceEntry, $this>
|
|
*/
|
|
public function providedServiceEntries(): HasMany
|
|
{
|
|
return $this->hasMany(ServiceEntry::class, 'provider_department_id');
|
|
}
|
|
|
|
/**
|
|
* Get the services received by the department.
|
|
*
|
|
* @return HasMany<ServiceEntry, $this>
|
|
*/
|
|
public function receivedServiceEntries(): HasMany
|
|
{
|
|
return $this->hasMany(ServiceEntry::class, 'recipient_department_id');
|
|
}
|
|
|
|
/**
|
|
* Get the attributes that should be cast.
|
|
*
|
|
* @return array<string, string>
|
|
*/
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'is_active' => 'boolean',
|
|
];
|
|
}
|
|
}
|