28 lines
672 B
PHP
28 lines
672 B
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Models;
|
||
|
|
|
||
|
|
use Illuminate\Database\Eloquent\Model;
|
||
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||
|
|
|
||
|
|
class Department extends Model
|
||
|
|
{
|
||
|
|
protected $fillable = ['name', 'code'];
|
||
|
|
|
||
|
|
// public function users(): HasMany
|
||
|
|
// {
|
||
|
|
// return $this->hasMany(User::class);
|
||
|
|
// }
|
||
|
|
|
||
|
|
// Relasi ke Posisi (dari tabel class_sections lama)
|
||
|
|
public function positions()
|
||
|
|
{
|
||
|
|
return $this->belongsToMany(Position::class, 'department_position');
|
||
|
|
}
|
||
|
|
|
||
|
|
// Relasi ke Karyawan (Users) untuk menghitung total karyawan di departemen ini
|
||
|
|
public function users()
|
||
|
|
{
|
||
|
|
return $this->hasMany(User::class, 'department_id');
|
||
|
|
}
|
||
|
|
}
|