title: Laravel: How to display the value of other table in a loop?
body: <p>So, I have this code which is printing the various topics/threads started by the user.</p>
  
  <p>It is looping over the <strong>Posts</strong> table that contains data related to posts.</p>
  
  <p>In <strong>User</strong> column, it will display <code>user_id</code>. But I want to access <strong>User</strong> table and display the <code>user_name</code> column matching that <code>user_id</code>. How to do this?</p>
  
  <pre><code>&lt;table border="2"&gt;
      &lt;tr&gt;
          &lt;th&gt;Topic&lt;/th&gt;
          &lt;th&gt;User&lt;/th&gt;
          &lt;th&gt;Replies&lt;/th&gt;
          &lt;th&gt;Views&lt;/th&gt;
          &lt;th&gt;Last Update&lt;/th&gt;
      &lt;/tr&gt;
      @foreach($topics as $topic)
          &lt;tr&gt;
              &lt;td&gt;&lt;a href="topics/{{$topic-&gt;id}}"&gt;{{$topic-&gt;topic_title}}&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;{{$topic-&gt;id}}&lt;/td&gt;
              &lt;td&gt;0&lt;/td&gt;
              &lt;td&gt;0&lt;/td&gt;
              &lt;td&gt;{{$topic-&gt;updated_at}}&lt;/td&gt;
          &lt;/tr&gt;
      @endforeach
  &lt;/table&gt;
  </code></pre>
  
  <p>Controller's Code:</p>
  
  <pre><code>public function show($id)
      {
          $topics = Topic::where('board_id', $id)-&gt;get();
          return view('boards.show')-&gt;with('topics', $topics);
      }
  </code></pre>