2025-11-24 16:52:23 +09:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
|
use Illuminate\Validation\Rule;
|
|
|
|
|
|
|
|
|
|
class UpdateDepartmentRequest 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');
|
|
|
|
|
$departmentId = $this->route('id'); // URL 파라미터에서 department ID 가져오기
|
|
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
'code' => [
|
|
|
|
|
'required',
|
|
|
|
|
'string',
|
|
|
|
|
'max:50',
|
|
|
|
|
Rule::unique('departments', 'code')
|
|
|
|
|
->where('tenant_id', $tenantId)
|
|
|
|
|
->ignore($departmentId),
|
|
|
|
|
],
|
|
|
|
|
'name' => 'required|string|max:100',
|
|
|
|
|
'description' => 'nullable|string|max:500',
|
|
|
|
|
'parent_id' => [
|
|
|
|
|
'nullable',
|
|
|
|
|
'exists:departments,id',
|
|
|
|
|
Rule::notIn([$departmentId]), // 자기 자신을 상위 부서로 설정 불가
|
|
|
|
|
],
|
|
|
|
|
'is_active' => 'nullable|boolean',
|
|
|
|
|
'sort_order' => 'nullable|integer|min:0',
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get custom attributes for validator errors.
|
|
|
|
|
*/
|
|
|
|
|
public function attributes(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
'code' => '부서 코드',
|
|
|
|
|
'name' => '부서명',
|
|
|
|
|
'description' => '설명',
|
|
|
|
|
'parent_id' => '상위 부서',
|
|
|
|
|
'is_active' => '활성 상태',
|
|
|
|
|
'sort_order' => '정렬 순서',
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the error messages for the defined validation rules.
|
|
|
|
|
*/
|
|
|
|
|
public function messages(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
'code.required' => '부서 코드는 필수입니다.',
|
|
|
|
|
'code.unique' => '이미 존재하는 부서 코드입니다.',
|
|
|
|
|
'code.max' => '부서 코드는 최대 50자까지 입력 가능합니다.',
|
|
|
|
|
'name.required' => '부서명은 필수입니다.',
|
|
|
|
|
'name.max' => '부서명은 최대 100자까지 입력 가능합니다.',
|
|
|
|
|
'description.max' => '설명은 최대 500자까지 입력 가능합니다.',
|
|
|
|
|
'parent_id.exists' => '유효하지 않은 상위 부서입니다.',
|
|
|
|
|
'parent_id.not_in' => '자기 자신을 상위 부서로 설정할 수 없습니다.',
|
|
|
|
|
'sort_order.min' => '정렬 순서는 0 이상이어야 합니다.',
|
|
|
|
|
];
|
|
|
|
|
}
|
2025-11-25 11:06:03 +09:00
|
|
|
}
|