userRepository = $userRepository; $this->hash = $hash; $this->tokenManager = $tokenManager; $this->currentUser = $currentUser; } public function login(UserLoginRequest $request) { /** @var User|null $user */ $user = $this->userRepository->getFirstWhere('email', $request->email); if (!$user || !$this->hash->check($request->password, $user->password)) { abort(Response::HTTP_UNAUTHORIZED, 'Invalid credentials'); } return response()->json([ 'token' => $this->tokenManager->createToken($user)->plainTextToken, ]); } public function logout() { $this->tokenManager->destroyTokens($this->currentUser); return response()->noContent(); } }