title: Laravel belongsTo relationship - Trying to get property of non-object
body: <h2>User.php</h2>
  
  <pre><code>class User extends Authenticatable
  {
      public function company() {
          return $this-&gt;belongsTo('App\Company');
      }
  }
  </code></pre>
  
  <h2>Company.php</h2>
  
  <pre><code>class Company extends Model
  {
      public function users() {
          return $this-&gt;hasMany('App\User');
      }
  }
  </code></pre>
  
  <h2>Table users</h2>
  
  <p>id name companies_id</p>
  
  <h2>Table companies</h2>
  
  <p>id name </p>
  
  <p>I'm trying to get the name of the company attached to the user.</p>
  
  <pre><code>$user = User::findOrFail(Auth::user()-&gt;id);
  $companyName = $user-&gt;company()-&gt;first()-&gt;name;
  </code></pre>
  
  <p>I got this error message <code>Trying to get property of non-object</code></p>
  
  <p>I don't get what I'm missing... Thank you in advance</p>