Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Http\Controllers\Auth;
  4.  
  5. use App\User;
  6. use App\Role;
  7. use App\Http\Controllers\Controller;
  8. use Illuminate\Support\Facades\Hash;
  9. use Illuminate\Support\Facades\Validator;
  10. use Illuminate\Foundation\Auth\RegistersUsers;
  11.  
  12. class RegisterController extends Controller
  13. {
  14. /*
  15. |--------------------------------------------------------------------------
  16. | Register Controller
  17. |--------------------------------------------------------------------------
  18. |
  19. | This controller handles the registration of new users as well as their
  20. | validation and creation. By default this controller uses a trait to
  21. | provide this functionality without requiring any additional code.
  22. |
  23. */
  24.  
  25. use RegistersUsers;
  26.  
  27. /**
  28. * Where to redirect users after registration.
  29. *
  30. * @var string
  31. */
  32. protected $redirectTo = '/home';
  33.  
  34. /**
  35. * Create a new controller instance.
  36. *
  37. * @return void
  38. */
  39. public function __construct()
  40. {
  41. $this->middleware('guest');
  42. }
  43.  
  44. /**
  45. * Get a validator for an incoming registration request.
  46. *
  47. * @param array $data
  48. * @return \Illuminate\Contracts\Validation\Validator
  49. */
  50. protected function validator(array $data)
  51. {
  52. return Validator::make($data, [
  53. 'name' => ['required', 'string', 'max:255'],
  54. 'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
  55. 'password' => ['required', 'string', 'min:8', 'confirmed'],
  56. ]);
  57. }
  58.  
  59. /**
  60. * Create a new user instance after a valid registration.
  61. *
  62. * @param array $data
  63. * @return \App\User
  64. */
  65. protected function create(array $data)
  66. {
  67. return User::create([
  68. 'name' => $data['name'],
  69. 'email' => $data['email'],
  70. 'password' => Hash::make($data['password']),
  71. ]);
  72.  
  73. $role_user = Role::where('name', 'users')->first();
  74. $user->roles()->attach($role_user);
  75. return $user;
  76. }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement