RegisterController.php 1.7 KB

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