- config/pagination.php 추가 (기본값 중앙 관리) - HasPagination Trait 추가 (prepareForValidation에서 자동 조정) - 22개 IndexRequest에 Trait 적용, max 규칙 제거 - 특수 케이스: Employee($maxSize=500), Audit($maxSize=200) size/per_page가 최대값 초과 시 422 오류 대신 최대값으로 자동 조정되어 리스트가 빈 화면으로 표시되는 문제 해결 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
62 lines
1.8 KiB
PHP
62 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use App\Http\Requests\Traits\HasPagination;
|
|
use App\Models\Tenants\Position;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class PositionRequest extends FormRequest
|
|
{
|
|
use HasPagination;
|
|
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public function rules(): array
|
|
{
|
|
$method = $this->method();
|
|
|
|
if ($method === 'GET') {
|
|
return [
|
|
'type' => ['nullable', Rule::in([Position::TYPE_RANK, Position::TYPE_TITLE])],
|
|
'is_active' => 'nullable|boolean',
|
|
'q' => 'nullable|string|max:100',
|
|
'per_page' => 'nullable|integer|min:1',
|
|
'page' => 'nullable|integer|min:1',
|
|
];
|
|
}
|
|
|
|
if ($method === 'POST') {
|
|
return [
|
|
'type' => ['required', Rule::in([Position::TYPE_RANK, Position::TYPE_TITLE])],
|
|
'name' => 'required|string|max:50',
|
|
'sort_order' => 'nullable|integer|min:0',
|
|
'is_active' => 'nullable|boolean',
|
|
];
|
|
}
|
|
|
|
if (in_array($method, ['PUT', 'PATCH'])) {
|
|
return [
|
|
'name' => 'nullable|string|max:50',
|
|
'sort_order' => 'nullable|integer|min:0',
|
|
'is_active' => 'nullable|boolean',
|
|
];
|
|
}
|
|
|
|
return [];
|
|
}
|
|
|
|
public function messages(): array
|
|
{
|
|
return [
|
|
'type.required' => __('validation.required', ['attribute' => '유형']),
|
|
'type.in' => __('validation.in', ['attribute' => '유형']),
|
|
'name.required' => __('validation.required', ['attribute' => '명칭']),
|
|
'name.max' => __('validation.max.string', ['attribute' => '명칭', 'max' => 50]),
|
|
];
|
|
}
|
|
} |