RegisterController.php 1.9 KB

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