/**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  \Closure $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $user_request = UserRequest::all();
     if (!$user_request->contains('token', $request->get('request_token'))) {
         return redirect()->route('home');
     }
     return $next($request);
 }
 public function save()
 {
     $user_request = new UserRequest();
     $user_request->token = bin2hex(random_bytes(15));
     $user_request->role = $this->string;
     $user_request->email = $this->email;
     $user_request->save();
     if ($this->string == 'Student') {
         $user = Student::where('email', $this->email)->first();
     } elseif ($this->string == 'Teacher') {
         $user = Teacher::where('email', $this->email)->first();
     }
     Mail::send('emails.reminder', ['user' => $user_request], function ($m) use($user) {
         $m->from('*****@*****.**', 'Your Account');
         $m->to($user->email, $user->name)->subject('Set up your account!');
     });
 }
 /**
  * Create a new user instance after a valid registration.
  *
  * @param  array $data
  * @return User
  */
 protected function create(array $data)
 {
     $user_request = UserRequest::where('token', $data['request_token'])->first();
     if ($user_request->role == "Student") {
         $user = Student::where('email', $user_request->email)->first();
     } else {
         if ($user_request->role == "Teacher") {
             $user = Teacher::where('email', $user_request->email)->first();
         }
     }
     $newUser = User::create(['name' => $user->name, 'email' => $user->email, 'password' => bcrypt($data['password'])]);
     $newUser->roles()->attach($user_request->role);
     $user_request->delete();
     return $newUser;
 }