Files
sam-manage/app/Http/Requests/UpdatePermissionRequest.php

76 lines
2.1 KiB
PHP
Raw Normal View History

<?php
namespace App\Http\Requests;
use App\Services\PermissionService;
use Illuminate\Foundation\Http\FormRequest;
class UpdatePermissionRequest 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
{
$permissionId = $this->route('id');
return [
'name' => [
'required',
'string',
'max:255',
function ($attribute, $value, $fail) use ($permissionId) {
$guardName = $this->input('guard_name', 'web');
$tenantId = $this->input('tenant_id');
$service = app(PermissionService::class);
if ($service->isNameExists($value, $guardName, $permissionId, $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' => '존재하지 않는 테넌트입니다.',
];
}
}