RegistrationForm.php 910 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace App\Http\Requests;
  3. use App\User;
  4. use Illuminate\Foundation\Http\FormRequest;
  5. class RegistrationForm extends FormRequest
  6. {
  7. /**
  8. * Determine if the user is authorized to make this request.
  9. *
  10. * @return bool
  11. */
  12. public function authorize()
  13. {
  14. return true;
  15. }
  16. /**
  17. * Custom code, not part of standard forms/requests.
  18. *
  19. * @return User
  20. */
  21. public function persist(): User
  22. {
  23. $user = User::create($this->only(['name', 'email', 'password']));
  24. return $user;
  25. }
  26. /**
  27. * Get the validation rules that apply to the request.
  28. *
  29. * @return array
  30. */
  31. public function rules()
  32. {
  33. return [
  34. 'name' => 'required',
  35. 'email' => 'required|email',
  36. // "confirmed" uses <field>_confirmation.
  37. 'password' => 'required|confirmed',
  38. ];
  39. }
  40. }