title: How can I delete the token when the user log out?
body: <p>I made a <strong>UserController</strong> which generats an <em><strong>accessToken</strong></em> when a user registered succesfully on a page.</p>
  <pre><code>class UserController extends Controller
  {
  
      /**
       * Login Method: in here we call Auth::attempt with the credentials the user supplied. 
       * If authentication is successful, we create access tokens and return them to the user. 
       * This access token is what the user would always send along with all API calls to have access to the APIs.
       * Register Method: like the login method, we validated the user information, 
       * created an account for the user and generated an access token for the user.
       */
      
      public function login()
          {
              $credentials = [
                  'email' =&gt; request('email'), 
                  'password' =&gt; request('password')
              ];
  
              if (Auth::attempt($credentials)) {
                  $success['token'] = Auth::user()-&gt;createToken('MyApp')-&gt;accessToken;
  
                  return response()-&gt;json(['success' =&gt; $success]);
              }
  
              $status = 401;
              $response = ['error' =&gt; 'Unauthorized'];
  
              return response()-&gt;json($response, $status);
          }
  
          public function register(Request $request)
          {
              $validator = Validator::make($request-&gt;all(), [
                  'name' =&gt; 'required',
                  'email' =&gt; 'required|email',
                  'password' =&gt; 'required',
              ]);
  
              if ($validator-&gt;fails()) {
                  return response()-&gt;json(['error' =&gt; $validator-&gt;errors()], 401);
              }
  
              $input = $request-&gt;all();
              $input['password'] = bcrypt($input['password']);
  
              $user = User::create($input);
              $success['token'] = $user-&gt;createToken('MyApp')-&gt;accessToken;
              $success['name'] = $user-&gt;name;
  
              return response()-&gt;json(['success' =&gt; $success]);
          }
  
          public function getDetails()
          {
              return response()-&gt;json(['success' =&gt; Auth::user()]);
          }
  }
  </code></pre>
  <p>My problem is that I want to remove the token when the user logs out but I dont know how to remove the access token from the user.</p>
  <p><strong>logout</strong> function in my <strong>UserController</strong></p>
  <pre><code> public function logout() 
          {
              Auth::user()-&gt;tokens-&gt;each(function($token, $key) {
                  $token-&gt;delete();
              });
          
              return response()-&gt;json([
                  'message' =&gt; 'Logged out successfully!',
                  'status_code' =&gt; 200
              ], 200);
          }
  </code></pre>
  <p>When I test it with <strong>postman</strong> with the <strong>GET</strong> route: <a href="http://127.0.0.1:8000/api/logout" rel="nofollow noreferrer">http://127.0.0.1:8000/api/logout</a>. Am I missing something?</p>
  <hr />
  <p>UPDATE</p>
  <p>Here s my <strong>api.php</strong> file:</p>
  <pre><code>Route::resource('categories', 'App\Http\Controllers\CategoryController');
  
  Route::post('register', 'App\Http\Controllers\UserController@register');
  Route::post('login', 'App\Http\Controllers\UserController@login');
  
  
  /**
   * We can group the routes we need auth for
   * under common middleware. It secures our routes
   */
  Route::group(['middleware' =&gt; 'auth:api'], function(){
  
   Route::get('logout', 'App\Http\Controllers\UserController@logout');
  });
  </code></pre>
  <p>I am testing it in postman using the route: <a href="http://127.0.0.1:8000/api/logout" rel="nofollow noreferrer">http://127.0.0.1:8000/api/logout</a> and passing the Bearer token, which I get from the login request, as a value.</p>