- DepartmentService, DepartmentController (Blade/API) 생성 - 부서 CRUD 기능 완성 (목록/생성/수정/삭제) - FormRequest 검증 (StoreDepartmentRequest, UpdateDepartmentRequest) - HTMX 패턴 적용 (index, create, edit, partials/table) - 계층 구조 지원 (parent-child relationships) - 활성/비활성 상태 관리 - 정렬 순서 관리 - Tenant Selector 통합 - Sidebar 메뉴에 부서 관리 추가 주요 기능: - 자기 참조 방지 (parent_id validation) - 하위 부서 존재 시 삭제 방지 - Conditional tenant filtering 적용 - Active/Inactive 필터링 - HTMX 페이지네이션 (target, includeForm 파라미터 포함) 정책: - 모든 리스트 화면은 1페이지만 있어도 페이지네이션 표시
72 lines
2.2 KiB
PHP
72 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class StoreDepartmentRequest 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 [
|
|
'code' => [
|
|
'required',
|
|
'string',
|
|
'max:50',
|
|
Rule::unique('departments', 'code')
|
|
->where('tenant_id', $tenantId),
|
|
],
|
|
'name' => 'required|string|max:100',
|
|
'description' => 'nullable|string|max:500',
|
|
'parent_id' => 'nullable|exists:departments,id',
|
|
'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' => '유효하지 않은 상위 부서입니다.',
|
|
'sort_order.min' => '정렬 순서는 0 이상이어야 합니다.',
|
|
];
|
|
}
|
|
} |