AuthController.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace App\Http\Controllers\Auth;
  3. use App\Models\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 = '/post';
  27. /**
  28. * Where to redirect users after logout.
  29. *
  30. * @var string
  31. */
  32. protected $redirectAfterLogout = '/post';
  33. /**
  34. * Create a new authentication controller instance.
  35. *
  36. * @return void
  37. */
  38. public function __construct()
  39. {
  40. $this->middleware('guest', ['except' => 'logout']);
  41. }
  42. /**
  43. * Get a validator for an incoming registration request.
  44. *
  45. * @param array $data
  46. * @return \Illuminate\Contracts\Validation\Validator
  47. */
  48. protected function validator(array $data)
  49. {
  50. return Validator::make($data, [
  51. 'name' => 'required|max:255',
  52. 'email' => 'required|email|max:255|unique:users',
  53. 'password' => 'required|confirmed|min:6',
  54. ]);
  55. }
  56. /**
  57. * Create a new user instance after a valid registration.
  58. *
  59. * @param array $data
  60. * @return User
  61. */
  62. protected function create(array $data)
  63. {
  64. return User::create([
  65. 'name' => $data['name'],
  66. 'email' => $data['email'],
  67. 'password' => bcrypt($data['password']),
  68. 'admin' => isset($data['admin'])
  69. ]);
  70. }
  71. }