userRepository = $userRepository; $this->hash = $hash; $this->currentUser = $currentUser; $this->tokenManager = $tokenManager; } public function login(UserLoginRequest $request) { /** @var User $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()->json(null, Response::HTTP_NO_CONTENT); } }