Nenhuma Descrição

RegisterController.php 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace App\Http\Controllers\Auth;
  3. use App\User;
  4. use App\Http\Controllers\Controller;
  5. use Illuminate\Support\Facades\Hash;
  6. use Illuminate\Support\Facades\Validator;
  7. use Illuminate\Foundation\Auth\RegistersUsers;
  8. class RegisterController extends Controller
  9. {
  10. /*
  11. |--------------------------------------------------------------------------
  12. | Register Controller
  13. |--------------------------------------------------------------------------
  14. |
  15. | This controller handles the registration of new users as well as their
  16. | validation and creation. By default this controller uses a trait to
  17. | provide this functionality without requiring any additional code.
  18. |
  19. */
  20. use RegistersUsers;
  21. /**
  22. * Where to redirect users after registration.
  23. *
  24. * @var string
  25. */
  26. protected $redirectTo = '/home';
  27. /**
  28. * Create a new controller instance.
  29. *
  30. * @return void
  31. */
  32. public function __construct()
  33. {
  34. $this->middleware('guest');
  35. }
  36. /**
  37. * Get a validator for an incoming registration request.
  38. *
  39. * @param array $data
  40. * @return \Illuminate\Contracts\Validation\Validator
  41. */
  42. protected function validator(array $data)
  43. {
  44. return Validator::make($data, [
  45. 'name' => ['required', 'string', 'max:255'],
  46. 'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
  47. 'password' => ['required', 'string', 'min:8', 'confirmed'],
  48. ]);
  49. }
  50. /**
  51. * Create a new user instance after a valid registration.
  52. *
  53. * @param array $data
  54. * @return \App\User
  55. */
  56. protected function create(array $data)
  57. {
  58. return User::create([
  59. 'name' => $data['name'],
  60. 'email' => $data['email'],
  61. 'password' => Hash::make($data['password']),
  62. ]);
  63. }
  64. }