middleware('guest')->except('logout'); } public function showLoginForm() { return view('agent.auth.login'); } protected function login(Request $request) { $credentials = $request->only('email', 'password'); $user = Telemedpro::where($this->username(), $credentials['email'])->first(); if ($user && Hash::check($credentials['password'], $user->password)) { // Auth::guard('agent')->login($user, $request->has('remember')); if ($this->guard('agent')->attempt( $this->credentials($request), $request->has('remember') )) { // dd($this->guard()); return redirect($this->redirectTo); } dd($this->guard()); // dd($user && Hash::check($credentials['password'], $user->password)); return redirect($this->redirectTo); } return back()->withErrors(['email' => 'Invalid credentials']); } public function redirectPath() { return "/agent"; } public function loginAgent(Request $request) { $validatedData = $request->validate([ 'email' => 'required|email', 'password' => 'required' ]); $patient = Telemedpro::where('email', $validatedData['email'])->first(); if (!$patient || !Hash::check($validatedData['password'], $patient->password)) { return response()->json([ 'message' => 'Invalid credentials' ], 422); } if (!$patient || $patient->status == 0) { return response()->json([ 'message' => 'Your account is undergoing verification.' ], 422); } $token = $patient->createToken('auth_token')->plainTextToken; return response()->json([ 'data' => $patient, 'access_token' => $token, 'token_type' => 'Bearer', ]); } }