- 역할 목록: 테넌트/Guard 컬럼 추가, Guard 필터 드롭다운 추가 - 역할 등록/수정: Guard 선택 기능 추가 (API/Web) - 권한 선택 UI를 메뉴 기반 매트릭스로 변경 (7가지 권한 유형) - 테넌트 미선택 시 역할 등록 차단 - pagination.js 디버그 로그 제거
58 lines
1.2 KiB
PHP
58 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Models\Tenants\Tenant;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|
use Spatie\Permission\Models\Permission;
|
|
|
|
class Role extends Model
|
|
{
|
|
protected $fillable = [
|
|
'tenant_id',
|
|
'name',
|
|
'description',
|
|
'guard_name',
|
|
];
|
|
|
|
protected $casts = [
|
|
'tenant_id' => 'integer',
|
|
];
|
|
|
|
/**
|
|
* 관계: 테넌트
|
|
*/
|
|
public function tenant(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Tenant::class, 'tenant_id');
|
|
}
|
|
|
|
/**
|
|
* 관계: 권한 (다대다)
|
|
*/
|
|
public function permissions(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(
|
|
Permission::class,
|
|
'role_has_permissions',
|
|
'role_id',
|
|
'permission_id'
|
|
);
|
|
}
|
|
|
|
/**
|
|
* 관계: 사용자 (다대다)
|
|
*/
|
|
public function users(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(
|
|
User::class,
|
|
'model_has_roles',
|
|
'role_id',
|
|
'model_id'
|
|
)->wherePivot('model_type', User::class);
|
|
}
|
|
}
|