RegisterController.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace App\Http\Controllers\Auth;
  3. use App\User;
  4. use App\Http\Controllers\Controller;
  5. use Illuminate\Support\Facades\Validator;
  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 registration.
  22. *
  23. * @var string
  24. */
  25. protected $redirectTo = '/home';
  26. /**
  27. * Create a new controller instance.
  28. */
  29. public function __construct()
  30. {
  31. $this->middleware('guest');
  32. }
  33. /**
  34. * Get a validator for an incoming registration request.
  35. *
  36. * @param array $data
  37. * @return \Illuminate\Contracts\Validation\Validator
  38. */
  39. protected function validator(array $data)
  40. {
  41. return Validator::make($data, [
  42. 'name' => 'required|string|max:255',
  43. 'email' => 'required|string|email|max:255|unique:users',
  44. 'password' => 'required|string|min:6|confirmed',
  45. ]);
  46. }
  47. /**
  48. * Create a new user instance after a valid registration.
  49. *
  50. * @param array $data
  51. * @return \App\User
  52. */
  53. protected function create(array $data)
  54. {
  55. return User::create([
  56. 'name' => $data['name'],
  57. 'email' => $data['email'],
  58. 'password' => bcrypt($data['password']),
  59. ]);
  60. }
  61. }