Files
sam-api/app/Models/Commons/Department.php
kent 73d06e03b0 fix : 권한관리 기능 추가 (각 기능 확인 필요)
- 메뉴관리
- 역할관리
- 부서관리
- 메뉴, 부서, 역할, 유저 - 권한 연동
2025-08-16 03:25:50 +09:00

53 lines
1.5 KiB
PHP

<?php
namespace App\Models\Commons;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use App\Traits\BelongsToTenant;
use App\Traits\ModelTrait;
class Department extends Model
{
use SoftDeletes, BelongsToTenant, ModelTrait;
protected $table = 'departments';
protected $fillable = [
'tenant_id','code','name','description','is_active','sort_order',
'created_by','updated_by','deleted_by',
];
protected $casts = [
'tenant_id' => 'integer',
'is_active' => 'integer',
'sort_order'=> 'integer',
];
/** Relations */
public function departmentUsers()
{
return $this->hasMany(DepartmentUser::class, 'department_id');
}
public function users()
{
// User 네임스페이스가 다르면 여기만 맞춰줘.
return $this->belongsToMany(\App\Models\User::class, 'department_user', 'department_id', 'user_id')
->withPivot(['tenant_id','is_primary','joined_at','left_at','created_at','updated_at','deleted_at'])
->withTimestamps();
}
public function departmentPermissions()
{
return $this->hasMany(DepartmentPermission::class, 'department_id');
}
public function permissions()
{
return $this->belongsToMany(\Spatie\Permission\Models\Permission::class, 'department_permissions', 'department_id', 'permission_id')
->withPivot(['tenant_id','menu_id','is_allowed','created_at','updated_at','deleted_at'])
->withTimestamps();
}
}