How to logout a user from API using laravel Passport

后端 未结 8 886
夕颜
夕颜 2020-12-12 16:38

I\'m currently using 2 projects. 1 front end (with laravel backend to communicate with API) and another laravel project (the API).

Now I use Laravel Passport to auth

8条回答
  •  伪装坚强ぢ
    2020-12-12 17:06

    I am using Laravel 6.12.0, below function is working for me.

    public function logout(Request $request){
                $accessToken = Auth::user()->token();
                $token= $request->user()->tokens->find($accessToken);
                $token->revoke();
                $response=array();
                $response['status']=1;
                $response['statuscode']=200;
                $response['msg']="Successfully logout";
                return response()->json($response)->header('Content-Type', 'application/json');
            }
    

提交回复
热议问题