AuthController.php 1.9 KB

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