AuthController.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. * Create a new authentication controller instance.
  23. *
  24. * @return void
  25. */
  26. public function __construct()
  27. {
  28. $this->middleware('guest', ['except' => 'getLogout']);
  29. }
  30. /**
  31. * Get a validator for an incoming registration request.
  32. *
  33. * @param array $data
  34. * @return \Illuminate\Contracts\Validation\Validator
  35. */
  36. protected function validator(array $data)
  37. {
  38. return Validator::make($data, [
  39. 'name' => 'required|max:255',
  40. 'email' => 'required|email|max:255|unique:users',
  41. 'password' => 'required|confirmed|min:6',
  42. ]);
  43. }
  44. /**
  45. * Create a new user instance after a valid registration.
  46. *
  47. * @param array $data
  48. * @return User
  49. */
  50. protected function create(array $data)
  51. {
  52. return User::create([
  53. 'name' => $data['name'],
  54. 'email' => $data['email'],
  55. 'password' => bcrypt($data['password']),
  56. ]);
  57. }
  58. }