RegisterController.php 3.8 KB

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