RegisterRequest.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace App\Http\Requests\Admin;
  3. use App\Models\User;
  4. use Illuminate\Foundation\Http\FormRequest;
  5. use Illuminate\Validation\Rules;
  6. class RegisterRequest extends FormRequest
  7. {
  8. /**
  9. * Determine if the user is authorized to make this request.
  10. */
  11. public function authorize(): bool
  12. {
  13. return true;
  14. }
  15. /**
  16. * Get the validation rules that apply to the request.
  17. *
  18. * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
  19. */
  20. public function rules(): array
  21. {
  22. return [
  23. 'name' => ['required', 'string', 'max:255'],
  24. 'email' => ['required', 'string', 'lowercase', 'email', 'max:255', 'unique:'.User::class],
  25. 'password' => ['required', 'confirmed', Rules\Password::defaults()]
  26. ];
  27. }
  28. public function messages(): array
  29. {
  30. return [
  31. 'name.required' => '请输入账号',
  32. 'email.required' => '请输入邮箱',
  33. 'password.required' => '请输入密码',
  34. 'password_confirmation.required' => '两次输入密码不一致',
  35. ];
  36. }
  37. }