title: How to get data from three related table with it's model relationships?
body: <p>I have three tables like these:</p>
  <p><strong>Expense:-</strong></p>
  <ol>
  <li>expense_id</li>
  <li>user_id</li>
  </ol>
  <p><strong>User:-</strong></p>
  <ol>
  <li>user_id</li>
  <li>employee_id</li>
  </ol>
  <p><strong>Employee:-</strong></p>
  <ol>
  <li>employee_id</li>
  <li>first_name</li>
  <li>last_name</li>
  </ol>
  <p>I want to get <code>first_name</code> and <code> last_name</code> from the employee table where <code>expense.user_id = user.user_id</code>, I tried something like bellow, but I did not get the correct data.</p>
  <p><strong>Expense model:-</strong></p>
  <pre><code> public function users(){
  
      return $this-&gt;hasOne(User::class,'user_id','user_id');
  }
  </code></pre>
  <p><strong>User model:-</strong></p>
  <pre><code>public function employee(){
      return $this-&gt;hasOne(Employee::class,'employee_id','user_id');
  }
  </code></pre>
  <p><strong>And employee model:-</strong></p>
  <pre><code>public function users()
  {
      return $this-&gt;belongsTo(User::class,'employee_id');
  }
  </code></pre>
  <p><strong>I called to view like this:-</strong></p>
  <pre><code>&lt;td&gt;{{$expense-&gt;users-&gt;employee-&gt;first_name .&quot; &quot; . $expense-&gt;users-&gt;employee-&gt;last_name }}&lt;/td&gt;
  </code></pre>
  <p>It shows data, but not as expected data.</p>
  <p>Where is my mistake and how it should be?
  please help!
  thanks!</p>