title: how to store JWT token in database
body: <p>I know I'll lose the purpose if I store <code>jwt</code> token in my database but for some reason, i want to store it, how can I do that?</p>
  
  <p>Controller</p>
  
  <pre><code>&lt;?php
  
  namespace App\Http\Controllers;
  
  use App\Http\Controllers\Controller;
  use Illuminate\Http\Request;
  use Tymon\JWTAuth\JWTAuth;
  
  class AuthController extends Controller
  {
  /**
   * @var \Tymon\JWTAuth\JWTAuth
   */
  protected $jwt;
  
  public function __construct(JWTAuth $jwt)
  {
      $this-&gt;jwt = $jwt;
  }
  
  public function postLogin(Request $request)
  {
      $this-&gt;validate($request, [
          'email'    =&gt; 'required|email|max:255',
          'password' =&gt; 'required',
      ]);
  
      try {
  
          if (! $token = $this-&gt;jwt-&gt;attempt($request-&gt;only('email', 'password'))) {
          $create_token = User::where('user_id', $login-&gt;user_id)-&gt;update(['token' =&gt; $token]);
              return response()-&gt;json(['user_not_found'], 404);
          }
          else {
          $create_token = User::where('user_id', auth()-&gt;user()-&gt;user_id)-&gt;update(['token' =&gt; $token]);
          }
  
      } catch (\Tymon\JWTAuth\Exceptions\TokenExpiredException $e) {
  
          return response()-&gt;json(['token_expired'], 500);
  
      } catch (\Tymon\JWTAuth\Exceptions\TokenInvalidException $e) {
  
          return response()-&gt;json(['token_invalid'], 500);
  
      } catch (\Tymon\JWTAuth\Exceptions\JWTException $e) {
  
          return response()-&gt;json(['token_absent' =&gt; $e-&gt;getMessage()], 500);
  
      }
  
      return response()-&gt;json(compact('token'));
  }
  
      public function logout(Request $request) 
  {
      $this-&gt;jwt-&gt;invalidate($this-&gt;jwt-&gt;getToken());
      return response()-&gt;json([
          'message' =&gt; 'User logged off successfully!'
      ], 200);
  }
  }
  </code></pre>
  
  <p>I tried the method above but i got error saying Call to undefined function App\Http\Controllers\auth()
  can anyone help me??</p>