마이페이지·관리자 회원 폼에는 이미 연락처 필드가 있으나 회원가입 폼에만 빠져 두 화면이 불일치했다. DB·모델·Resource는 기존 존재하므로 회원가입 경로에만 검증·저장·입력 UI를 연결한다. 연락처는 선택 항목이다.
72 lines
2.7 KiB
PHP
72 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Auth;
|
|
|
|
use App\Extension\HookManager;
|
|
use App\Models\User;
|
|
use Illuminate\Contracts\Validation\ValidationRule;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class RegisterRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*
|
|
* @return bool 항상 true (권한은 미들웨어 체인에서 처리)
|
|
*/
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array<string, ValidationRule|array<mixed>|string>
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
$rules = [
|
|
'name' => 'required|string|max:255',
|
|
'nickname' => 'nullable|string|max:50',
|
|
'email' => ['required', 'string', 'email', 'max:255', Rule::unique(User::class)],
|
|
'password' => 'required|string|min:8|confirmed',
|
|
'mobile' => ['nullable', 'string', 'max:20', 'regex:/^[0-9\-\+\(\)\s]+$/'],
|
|
'phone' => ['nullable', 'string', 'max:20', 'regex:/^[0-9\-\+\(\)\s]+$/'],
|
|
'language' => 'nullable|string|in:'.implode(',', config('app.supported_locales', ['ko', 'en'])),
|
|
'agree_terms' => 'accepted',
|
|
'agree_privacy' => 'accepted',
|
|
];
|
|
|
|
// 모듈/플러그인이 validation rules를 동적으로 추가할 수 있도록 훅 제공
|
|
return HookManager::applyFilters('core.auth.register_validation_rules', $rules, $this);
|
|
}
|
|
|
|
/**
|
|
* Get custom messages for validator errors.
|
|
*
|
|
* @return array<string, string>
|
|
*/
|
|
public function messages(): array
|
|
{
|
|
return [
|
|
'name.required' => __('validation.auth.name.required'),
|
|
'name.max' => __('validation.auth.name.max'),
|
|
'nickname.max' => __('validation.auth.nickname.max'),
|
|
'email.required' => __('validation.auth.email.required'),
|
|
'email.email' => __('validation.auth.email.email'),
|
|
'email.unique' => __('validation.auth.email.unique'),
|
|
'password.required' => __('validation.auth.password.required'),
|
|
'password.min' => __('validation.auth.password.min'),
|
|
'password.confirmed' => __('validation.auth.password.confirmed'),
|
|
'mobile.max' => __('validation.auth.mobile.max'),
|
|
'mobile.regex' => __('validation.auth.mobile.regex'),
|
|
'phone.max' => __('validation.auth.phone.max'),
|
|
'phone.regex' => __('validation.auth.phone.regex'),
|
|
'agree_terms.accepted' => __('validation.auth.agree_terms.accepted'),
|
|
'agree_privacy.accepted' => __('validation.auth.agree_privacy.accepted'),
|
|
];
|
|
}
|
|
}
|