48 lines
1.3 KiB
PHP
48 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
class RegisterRequest 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
|
|
{
|
|
return [
|
|
'name' => 'required|string|max:50',
|
|
'email' => 'required|string|email|unique:users,email',
|
|
'password' => 'required|string|min:6|confirmed',
|
|
'phone' => 'nullable|string|max:20',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Get custom messages for validator errors.
|
|
*/
|
|
public function messages(): array
|
|
{
|
|
return [
|
|
'name.required' => '姓名不能为空',
|
|
'name.max' => '姓名最多50个字符',
|
|
'email.required' => '邮箱不能为空',
|
|
'email.email' => '邮箱格式不正确',
|
|
'email.unique' => '邮箱已被注册',
|
|
'password.required' => '密码不能为空',
|
|
'password.min' => '密码至少6个字符',
|
|
'password.confirmed' => '两次密码不一致',
|
|
];
|
|
}
|
|
} |