RegisterController.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. namespace App\Http\Controllers\TeacherAuth;
  3. use Validator;
  4. use App\Http\Controllers\Controller;
  5. use Illuminate\Http\Request;
  6. use Illuminate\Foundation\Auth\RegistersUsers;
  7. use Illuminate\Support\Facades\Auth;
  8. use App\User;
  9. use Hash;
  10. class RegisterController extends Controller
  11. {
  12. /*
  13. |--------------------------------------------------------------------------
  14. | Register Controller
  15. |--------------------------------------------------------------------------
  16. |
  17. | This controller handles the registration of new users as well as their
  18. | validation and creation. By default this controller uses a trait to
  19. | provide this functionality without requiring any additional code.
  20. |
  21. */
  22. use RegistersUsers;
  23. /**
  24. * Where to redirect users after login / registration.
  25. *
  26. * @var string
  27. */
  28. //protected $redirectTo = '/login-v2';
  29. /**
  30. * Create a new controller instance.
  31. *
  32. * @return void
  33. */
  34. public function __construct()
  35. {
  36. $this->middleware('teacher.guest');
  37. }
  38. /**
  39. * Get a validator for an incoming registration request.
  40. *
  41. * @param array $data
  42. * @return \Illuminate\Contracts\Validation\Validator
  43. */
  44. protected function validator(array $data)
  45. {
  46. return Validator::make($data, [
  47. 'firstname' => ['required', 'string', 'max:255'],
  48. 'lastname' => ['required', 'string', 'max:255'],
  49. 'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
  50. 'password' => ['required', 'string', 'min:8', 'confirmed'],
  51. //'phonenumber' => ['required', 'string', 'max:255'],
  52. 'universityname' => ['required', 'string', 'max:255'],
  53. 'department' => ['required', 'string', 'max:255'],
  54. 'designation' => ['required', 'string', 'max:255'],
  55. 'universitywebsite' => ['required', 'string', 'max:255'],
  56. ]);
  57. }
  58. /**
  59. * Create a new user instance after a valid registration.
  60. *
  61. * @param array $data
  62. * @return User
  63. */
  64. protected function create(Request $req)
  65. {
  66. $data = User::create([
  67. 'first_name' => $req->firstname,
  68. 'last_name' => $req->lastname,
  69. 'password' => Hash::make($req->password),
  70. 'email' => $req->email,
  71. // 'phone_number' => $req->phonenumber,
  72. 'university_name' => $req->universityname,
  73. 'department' => $req->department,
  74. 'designation' => $req->designation,
  75. 'uni_website' => $req->universitywebsite,
  76. 'user_type' => $req->user_type,
  77. 'ref_no' => name_initials($req->firstname,$req->lastname).''.teacherRefNoGenerate(),
  78. ]);
  79. Mail::to('test@mail.com')->send(new SignUp($data->id));
  80. return redirect("/teacher_profile");
  81. }
  82. /**
  83. * Show the application registration form.
  84. *
  85. * @return \Illuminate\Http\Response
  86. */
  87. public function showRegistrationForm()
  88. {
  89. return view('register-v2');
  90. }
  91. /**
  92. * Get the guard to be used during registration.
  93. *
  94. * @return \Illuminate\Contracts\Auth\StatefulGuard
  95. */
  96. protected function guard()
  97. {
  98. return Auth::guard('teacher');
  99. }
  100. }