Search code examples
phplaravellaravel-5angular5laravel-passport

Laravel logout function is not working


I am creating a project using laravel as the backend and angular 5 angular 5 as the front end. While accessing laravel functions through API calls from angular for logout it gives an error message

exception:"BadMethodCallException" file:"/path/vendor/laravel/framework/src/Illuminate/Support/Traits/Macroable.php" line:96 message:"Method logout does not exist."`

public function getlogout() {

    if (Auth::logout()) {
        return response()->json(['status' => true, 'message' => 'Successfully logged out']);
    }

}

please, someone, help me as I am new to laravel.


Solution

  • I use the laravel-passport and do so:

    public function logout()
    {
        $user = auth()->user();
    
        $user->token()->revoke();
        event(new Logout($user));
    
        return return response()->json(['status' => true, 'message' => 'Successfully logged out']);
    }