title: Getting data from laravel relation on Foreign Key
body: <p>I have to SQL tables: <code>users</code> and <code>roles</code>; The user table consists of an <code>id (PRIMARY)</code>, <code>email</code>, <code>password</code> and a <code>role_id (INDEX)</code> column. The role table consists of an <code>id (PRIMARY)</code> and a <code>name</code> column. A user can only have a single role (Admin or User).</p>
  
  <p>This is how my laravel Models look like:</p>
  
  <pre><code>// User Model
  public function role()
  {
      return $this-&gt;hasOne(Role::class);
  }
  
  // Role model
  public function user()
  {
      return $this-&gt;belongsTo(User::class);
  }
  </code></pre>
  
  <p>What i want is, when i get the information of a user, i want to get the corresponding role of that user.</p>
  
  <p>When i place this code in the Artisan Tinker:</p>
  
  <pre><code>// Get user with id=2
  App\User::find(2)-&gt;role;
  </code></pre>
  
  <p>This seems logical to me <code>"Find the role belonging to the user with id 2"</code></p>
  
  <p>But it is throwing this error:</p>
  
  <pre><code>Illuminate\Database\QueryException with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'roles.user_id' in 'where clause' (SQL: select * from `roles` where `roles`.`user_id` = 2 and `roles`.`user_id` is not null limit 1)'
  </code></pre>
  
  <p>How Can i get the role of a User without calling it from the Role model?</p>