67 lines
1.6 KiB
PHP
67 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Layout;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
/**
|
|
* 레이아웃 미리보기 생성 요청 검증
|
|
*
|
|
* 편집 중인 레이아웃 content를 임시 저장하여 미리보기를 생성합니다.
|
|
*/
|
|
class StoreLayoutPreviewRequest extends FormRequest
|
|
{
|
|
/**
|
|
* 사용자가 이 요청을 수행할 권한이 있는지 확인
|
|
*
|
|
* 권한 체크는 라우트의 permission 미들웨어에서 수행됩니다.
|
|
*/
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* 검증 전 데이터 전처리
|
|
*
|
|
* content가 JSON 문자열로 전송된 경우 배열로 변환합니다.
|
|
*/
|
|
protected function prepareForValidation(): void
|
|
{
|
|
$content = $this->input('content');
|
|
|
|
if (is_string($content)) {
|
|
$decoded = json_decode($content, true);
|
|
|
|
if (json_last_error() === JSON_ERROR_NONE && is_array($decoded)) {
|
|
$this->merge(['content' => $decoded]);
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 요청에 적용할 검증 규칙
|
|
*
|
|
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'content' => ['required', 'array'],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* 검증 오류 메시지 커스터마이징
|
|
*
|
|
* @return array<string, string>
|
|
*/
|
|
public function messages(): array
|
|
{
|
|
return [
|
|
'content.required' => __('validation.layout.content.required'),
|
|
'content.array' => __('validation.layout.content.array'),
|
|
];
|
|
}
|
|
}
|