- 수입검사 저장 시 rendered_html이 Nginx 제한 초과하여 413 발생하던 문제 - max:512000 검증 추가로 413 대신 422(명확한 에러메시지) 반환
56 lines
2.1 KiB
PHP
56 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Document;
|
|
|
|
use App\Models\Documents\DocumentAttachment;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
class UpsertRequest extends FormRequest
|
|
{
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public function rules(): array
|
|
{
|
|
$attachmentTypes = implode(',', DocumentAttachment::TYPES);
|
|
|
|
return [
|
|
// 필수: 템플릿 + 품목
|
|
'template_id' => 'required|integer|exists:document_templates,id',
|
|
'item_id' => 'required|integer',
|
|
'title' => 'nullable|string|max:255',
|
|
|
|
// 문서 데이터 (EAV)
|
|
'data' => 'nullable|array',
|
|
'data.*.section_id' => 'nullable|integer',
|
|
'data.*.column_id' => 'nullable|integer',
|
|
'data.*.row_index' => 'nullable|integer|min:0',
|
|
'data.*.field_key' => 'required_with:data|string|max:100',
|
|
'data.*.field_value' => 'nullable|string',
|
|
|
|
// HTML 스냅샷 (500KB 제한 — 초과 시 413 대신 422 반환)
|
|
'rendered_html' => 'nullable|string|max:512000',
|
|
|
|
// 첨부파일
|
|
'attachments' => 'nullable|array',
|
|
'attachments.*.file_id' => 'required_with:attachments|integer|exists:files,id',
|
|
'attachments.*.attachment_type' => "nullable|string|in:{$attachmentTypes}",
|
|
'attachments.*.description' => 'nullable|string|max:255',
|
|
];
|
|
}
|
|
|
|
public function messages(): array
|
|
{
|
|
return [
|
|
'template_id.required' => __('validation.required', ['attribute' => '템플릿']),
|
|
'template_id.exists' => __('validation.exists', ['attribute' => '템플릿']),
|
|
'item_id.required' => __('validation.required', ['attribute' => '품목 ID']),
|
|
'data.*.field_key.required_with' => __('validation.required', ['attribute' => '필드 키']),
|
|
'attachments.*.file_id.exists' => __('validation.exists', ['attribute' => '파일']),
|
|
'rendered_html.max' => 'HTML 스냅샷이 너무 큽니다. (최대 500KB)',
|
|
];
|
|
}
|
|
}
|