- Permission 모델 및 PermissionService 생성 (Spatie Permission 확장) - HTMX 기반 권한 CRUD API 구현 - Blade 기반 권한 관리 화면 (index, create, edit) - 권한명 포맷팅 로직 추가 (menu:id.type 파싱) - 사이드바 메뉴 추가 - 멀티테넌트 지원 (tenant_id nullable) - 할당된 역할/부서 표시 기능
74 lines
2.0 KiB
PHP
74 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use App\Services\PermissionService;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
class StorePermissionRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*/
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'name' => [
|
|
'required',
|
|
'string',
|
|
'max:255',
|
|
function ($attribute, $value, $fail) {
|
|
$guardName = $this->input('guard_name', 'web');
|
|
$tenantId = $this->input('tenant_id');
|
|
|
|
$service = app(PermissionService::class);
|
|
if ($service->isNameExists($value, $guardName, null, $tenantId)) {
|
|
$fail('이 권한 이름은 이미 사용 중입니다.');
|
|
}
|
|
},
|
|
],
|
|
'guard_name' => 'required|string|max:255',
|
|
'tenant_id' => 'nullable|exists:tenants,id',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Get custom attributes for validator errors.
|
|
*
|
|
* @return array<string, string>
|
|
*/
|
|
public function attributes(): array
|
|
{
|
|
return [
|
|
'name' => '권한 이름',
|
|
'guard_name' => '가드 이름',
|
|
'tenant_id' => '테넌트',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Get custom messages for validator errors.
|
|
*
|
|
* @return array<string, string>
|
|
*/
|
|
public function messages(): array
|
|
{
|
|
return [
|
|
'name.required' => '권한 이름을 입력해주세요.',
|
|
'name.max' => '권한 이름은 255자를 초과할 수 없습니다.',
|
|
'guard_name.required' => '가드 이름을 입력해주세요.',
|
|
'tenant_id.exists' => '존재하지 않는 테넌트입니다.',
|
|
];
|
|
}
|
|
}
|