title: Laravel - Trying to get property 'token' of non-object", exception: "ErrorException"
body: <p>I am using Angular-7 as frontend and Laravel-5.8 as backend for a web application.</p>
  
  <p>ApiController.php</p>
  
  <pre><code> public function login(Request $request)
   {
     $request-&gt;validate([
      'email' =&gt; 'required|string|email',
      'password' =&gt; 'required|string',
      'remember_me' =&gt; 'boolean'
      ]);
      $credentials = request(['email', 'password']);
      $credentials['active'] = 1;
      $credentials['deleted_at'] = null;
      if(!Auth::attempt($credentials))
      return response()-&gt;json([
        'message' =&gt; 'Unauthorized'
      ], 401);
  
      $user = $request-&gt;user();
      $res = User::with('roles')-&gt;find($user-&gt;id);
      $tokenResult = $user-&gt;createToken('MyApp')-&gt;accessToken;
      $token = $tokenResult-&gt;token;
      if ($request-&gt;remember_me)
      $token-&gt;expires_at = Carbon::now()-&gt;addWeeks(13);
      $token-&gt;save();
      return response()-&gt;json([
        'access_token' =&gt; $tokenResult-&gt;accessToken,
        'token_type' =&gt; 'Bearer',
        'expires_at' =&gt; Carbon::parse($tokenResult-&gt;token-&gt;expires_at)-&gt;toDateTimeString(),
              'user' =&gt; response()-&gt;json($res)-&gt;original
          ]);
      }
  </code></pre>
  
  <p>From the Angular frontend, when I click on submit on the Login Page, it suppose to redirect to home page. But I got this error:</p>
  
  <blockquote>
    <p>{message: "Trying to get property 'token' of non-object", exception: "ErrorException", file: "C:\xampp\htdocs\clientportal-app\backend\app\Http\Controllers\ApiController.php", line: 212, trace: Array(35)}</p>
  </blockquote>
  
  <p>When I checked line 212 from Laravel ApiController from the code above, this is what I have:</p>
  
  <blockquote>
    <p>$token = $tokenResult->token;</p>
  </blockquote>
  
  <p>How do I resolve it?</p>