66 lines
1.8 KiB
PHP
66 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class StoreRoleRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*/
|
|
public function authorize(): bool
|
|
{
|
|
return true; // 권한 체크는 middleware에서 처리
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
$tenantId = session('selected_tenant_id');
|
|
|
|
return [
|
|
'name' => [
|
|
'required',
|
|
'string',
|
|
'max:100',
|
|
Rule::unique('roles', 'name')
|
|
->where('tenant_id', $tenantId)
|
|
->where('guard_name', 'web'),
|
|
],
|
|
'description' => 'nullable|string|max:500',
|
|
'permissions' => 'nullable|array',
|
|
'permissions.*' => 'exists:permissions,id',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Get custom attributes for validator errors.
|
|
*/
|
|
public function attributes(): array
|
|
{
|
|
return [
|
|
'name' => '역할 이름',
|
|
'description' => '설명',
|
|
'permissions' => '권한',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Get the error messages for the defined validation rules.
|
|
*/
|
|
public function messages(): array
|
|
{
|
|
return [
|
|
'name.required' => '역할 이름은 필수입니다.',
|
|
'name.unique' => '이미 존재하는 역할 이름입니다.',
|
|
'name.max' => '역할 이름은 최대 100자까지 입력 가능합니다.',
|
|
'description.max' => '설명은 최대 500자까지 입력 가능합니다.',
|
|
'permissions.*.exists' => '유효하지 않은 권한이 포함되어 있습니다.',
|
|
];
|
|
}
|
|
}
|