RegisterController.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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\Mail\SignUp;
  9. use App\User;
  10. use App\Models\Department;
  11. use App\Models\University;
  12. use Hash;
  13. use Mail;
  14. class RegisterController extends Controller
  15. {
  16. /*
  17. |--------------------------------------------------------------------------
  18. | Register Controller
  19. |--------------------------------------------------------------------------
  20. |
  21. | This controller handles the registration of new users as well as their
  22. | validation and creation. By default this controller uses a trait to
  23. | provide this functionality without requiring any additional code.
  24. |
  25. */
  26. //use RegistersUsers;
  27. /**
  28. * Where to redirect users after login / registration.
  29. *
  30. * @var string
  31. */
  32. //protected $redirectTo = '/login-v2';
  33. /**
  34. * Create a new controller instance.
  35. *
  36. * @return void
  37. */
  38. public function __construct()
  39. {
  40. $this->middleware('teacher.guest');
  41. }
  42. protected function validator(array $data)
  43. {
  44. return Validator::make($data, [
  45. 'firstname' => ['required', 'string', 'max:255'],
  46. 'lastname' => ['required', 'string', 'max:255'],
  47. 'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
  48. 'password' => ['required', 'string', 'min:8', 'confirmed'],
  49. //'phonenumber' => ['required', 'string', 'max:255'],
  50. 'universityname' => ['required', 'string', 'max:255'],
  51. 'department' => ['required', 'string', 'max:255'],
  52. 'designation' => ['required', 'string', 'max:255'],
  53. 'universitywebsite' => ['required', 'string', 'max:255'],
  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(Request $req)
  63. {
  64. $user_data = User::create([
  65. 'first_name' => $req->firstname,
  66. 'last_name' => $req->lastname,
  67. 'password' => Hash::make($req->password),
  68. 'email' => $req->email,
  69. // 'phone_number' => $req->phonenumber,
  70. 'university_name' => $req->university,
  71. 'department' => $req->department,
  72. 'others_department' => $req->others_department,
  73. 'designation' => $req->designation,
  74. 'uni_website' => $req->universitywebsite,
  75. 'user_type' => $req->user_type,
  76. 'ref_no' => name_initials($req->firstname,$req->lastname).''.teacherRefNoGenerate(),
  77. ]);
  78. //Mail::to('test@mail.com')->send(new SignUp($data->id));
  79. $data['name'] = $user_data->first_name.' '.$user_data->last_name;
  80. $user_mail = $user_data->email;
  81. $from = 'asraful@revinr.com';
  82. Mail::send('email.register_teacher_email',$data, function ($message) use ($user_mail,$from) {
  83. $message->from($from);
  84. $message->to($user_mail)->subject('New Email Send to you');
  85. });
  86. return redirect()->to("/login-v2")->with('success','Your registration successfully saved. Please check your email for verification login.');
  87. }
  88. /**
  89. * Show the application registration form.
  90. *
  91. * @return \Illuminate\Http\Response
  92. */
  93. public function showRegistrationForm()
  94. {
  95. $departments =Department::where('status',1)->orderBy('name','ASC')->get();
  96. $universities =University::orderBy('name','ASC')->get();
  97. return view('register-v2',compact('departments','universities'));
  98. }
  99. /**
  100. * Get the guard to be used during registration.
  101. *
  102. * @return \Illuminate\Contracts\Auth\StatefulGuard
  103. */
  104. protected function guard()
  105. {
  106. return Auth::guard('teacher');
  107. }
  108. }