当我使用 api 注销并再次发送获取请求以显示用户数据时,它显示 "Route [login] not defined."

when i logout using api and i again send a get request to show the user data, it shows "Route [login] not defined."

我的问题:- 使用 api post 请求注销后,我发送了获取用户详细信息请求,它显示一条消息 "Route [login] not defined.".

我的登出密码:-

public function logout(Request $request) {

    $request->user()->token()->revoke();

    $json = [
            'success' => true,

            'code' => 200,

            'message' => 'You are Logged out.',

        ];

        return response()->json($json, '200');
}

1: https://i.stack.imgur.com/wiGQz.png

您正在尝试重定向到名称为 loginnamed route,但您没有具有该名称的路由:

Route::post('login', 'AuthController@login')->name('login'); 

app\Exceptions\Handler.php 试试这个它帮助了我以前的

您可以在 laravel 中覆盖它。只需确保包括

use Exception;
use Request;
use Illuminate\Auth\AuthenticationException;
use Response;

 protected function unauthenticated($request, AuthenticationException $exception)
    {
        if ($request->expectsJson()) {
            return response()->json(['error' => 'Unauthenticated.'], 401);
        }


        return redirect()->route('auth.login');
    }

不允许的方法405错误它是路由或 csrf 保护的问题试试这个

Route::get('logout', 'AuthController@logout');