AuthController.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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\ThrottlesLogins;
  7. use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
  8. class AuthController extends Controller
  9. {
  10. /*
  11. |--------------------------------------------------------------------------
  12. | Registration & Login Controller
  13. |--------------------------------------------------------------------------
  14. |
  15. | This controller handles the registration of new users, as well as the
  16. | authentication of existing users. By default, this controller uses
  17. | a simple trait to add these behaviors. Why don't you explore it?
  18. |
  19. */
  20. use AuthenticatesAndRegistersUsers, ThrottlesLogins;
  21. /**
  22. * Where to redirect users after login / registration.
  23. *
  24. * @var string
  25. */
  26. protected $redirectTo = '/';
  27. /**
  28. * Create a new authentication controller instance.
  29. *
  30. * @return void
  31. */
  32. public function __construct()
  33. {
  34. $this->middleware('guest', ['except' => 'logout']);
  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|max:255',
  46. 'email' => 'required|email|max:255|unique:users',
  47. 'password' => 'required|confirmed|min:6',
  48. ]);
  49. }
  50. /**
  51. * Create a new user instance after a valid registration.
  52. *
  53. * @param array $data
  54. * @return User
  55. */
  56. protected function create(array $data)
  57. {
  58. return User::create([
  59. 'name' => $data['name'],
  60. 'email' => $data['email'],
  61. 'password' => bcrypt($data['password']),
  62. ]);
  63. }
  64. }