I figured out what happened. Before you can log a user out via API, you will need to pass authentication first and then log your login off. Therefore the route logout has to be underneath the middleware auth. For convenience I grouped it with the /user route that is used in this tutorial.
I got it
public function logout (Request $request) {
$accessToken = auth()->user()->token();
$token= $request->user()->tokens->find($accessToken);
$token->revoke();
This makes sense I however got this error, do not know why,
Call to a member function token() on null
I figured out what happened. Before you can log a user out via API, you will need to pass authentication first and then log your login off. Therefore the route
logout
has to be underneath the middleware auth. For convenience I grouped it with the/user
route that is used in this tutorial.Thankyou Sir