Nav apraksta

RegisterController.php 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace App\Http\Controllers\Auth;
  3. use App\User;
  4. use App\Http\Controllers\Controller;
  5. use Illuminate\Support\Facades\Hash;
  6. use Illuminate\Support\Facades\Validator;
  7. use Illuminate\Foundation\Auth\RegistersUsers;
  8. class RegisterController extends Controller
  9. {
  10. /*
  11. |--------------------------------------------------------------------------
  12. | Register Controller
  13. |--------------------------------------------------------------------------
  14. |
  15. | This controller handles the registration of new users as well as their
  16. | validation and creation. By default this controller uses a trait to
  17. | provide this functionality without requiring any additional code.
  18. |
  19. */
  20. use RegistersUsers;
  21. /**
  22. * Where to redirect users after registration.
  23. *
  24. * @var string
  25. */
  26. protected $redirectTo = '/home';
  27. /**
  28. * Create a new controller instance.
  29. *
  30. * @return void
  31. */
  32. public function __construct()
  33. {
  34. $this->middleware('guest');
  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', 'string', 'max:255'],
  46. 'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
  47. 'password' => ['required', 'string', 'min:8', 'confirmed'],
  48. ]);
  49. }
  50. /**
  51. * Create a new user instance after a valid registration.
  52. *
  53. * @param array $data
  54. * @return \App\User
  55. */
  56. protected function create(array $data)
  57. {
  58. return User::create([
  59. 'name' => $data['name'],
  60. 'email' => $data['email'],
  61. 'password' => Hash::make($data['password']),
  62. ]);
  63. }
  64. }