- 트리 구조 정렬 및 표시 (무제한 depth 지원) - 접기/펼치기 기능 추가 (재귀적 처리) - 활성/숨김 상태 토글 기능 (실시간 업데이트) - 테넌트 필터링 (전체 선택 시 마스터 메뉴만 표시) - UI 개선 (토글 버튼, 외부 메뉴 표시) 추가된 파일: - MenuService: 비즈니스 로직 처리 - MenuController (API/Web): 라우트 처리 - MenuRequest: 유효성 검증 - views/menus/: 메뉴 관리 뷰 수정된 파일: - routes/api.php, web.php: 메뉴 라우트 추가
81 lines
2.3 KiB
PHP
81 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
class UpdateMenuRequest 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
|
|
{
|
|
$menuId = $this->route('id');
|
|
|
|
return [
|
|
'parent_id' => [
|
|
'nullable',
|
|
'exists:menus,id',
|
|
function ($attribute, $value, $fail) use ($menuId) {
|
|
// 자기 자신을 부모로 설정 방지
|
|
if ($value == $menuId) {
|
|
$fail('자기 자신을 부모 메뉴로 설정할 수 없습니다.');
|
|
}
|
|
},
|
|
],
|
|
'name' => 'required|string|max:100',
|
|
'url' => 'nullable|string|max:255',
|
|
'icon' => 'nullable|string|max:100',
|
|
'sort_order' => 'nullable|integer|min:0',
|
|
'is_active' => 'nullable|boolean',
|
|
'hidden' => 'nullable|boolean',
|
|
'is_external' => 'nullable|boolean',
|
|
'external_url' => 'nullable|string|max:255|required_if:is_external,1',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Get custom attributes for validator errors.
|
|
*
|
|
* @return array<string, string>
|
|
*/
|
|
public function attributes(): array
|
|
{
|
|
return [
|
|
'parent_id' => '부모 메뉴',
|
|
'name' => '메뉴명',
|
|
'url' => 'URL',
|
|
'icon' => '아이콘',
|
|
'sort_order' => '정렬 순서',
|
|
'is_active' => '활성 상태',
|
|
'hidden' => '숨김 여부',
|
|
'is_external' => '외부 링크',
|
|
'external_url' => '외부 URL',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Get custom messages for validator errors.
|
|
*
|
|
* @return array<string, string>
|
|
*/
|
|
public function messages(): array
|
|
{
|
|
return [
|
|
'parent_id.exists' => '존재하지 않는 부모 메뉴입니다.',
|
|
'external_url.required_if' => '외부 링크 사용 시 외부 URL은 필수입니다.',
|
|
];
|
|
}
|
|
}
|