title: Laravel - Retrieving a username using two tables with both having the userID
body: <p>What's up fellow StackOverflow users,</p>
  
  <p>The thing that I am trying to accomplish is to basicly retrieve the username of someone with only the availability of the person's user_id.</p>
  
  <p>My project is using two different tables, one is for the articles, and the other one is for the user-data.</p>
  
  <p>I am currently displaying all of the articles into a view, but I also want to display the author's name of each post, with only access to the user_id.</p>
  
  <p><em>The method inside of my controller which I'm using:</em></p>
  
  <pre><code>    public function index() {
      $posts = Index::all();
  
      return view('index', ['posts' =&gt; $posts]);
  }
  </code></pre>
  
  <p><em>The view where I want to display the username in to:</em></p>
  
  <pre><code>@extends('layouts.app')
  
  @section('content')
      &lt;div class="container mt-5"&gt;
          &lt;div class="col-12"&gt;
              @if(!Auth::check())
              &lt;ul class="list-group"&gt;
                  &lt;li class="list-group-item mb-3"&gt;&lt;h1 class="h1"&gt;Become a member now&lt;/h1&gt;
                      &lt;h5 class="h5"&gt;Discuss your favourite topics with the internet&lt;/h5&gt;
                      &lt;a href="{!! url()-&gt;current() !!}/register"&gt;&lt;button type="button" class="btn btn-dark"&gt;Get started&lt;/button&gt;&lt;/a&gt;
                  &lt;/li&gt;
              &lt;/ul&gt;
              @endif
              @if(count($posts) &gt; 0)
                  &lt;ul class="list-group"&gt;
                      @foreach ($posts as $post)
                          &lt;li class="list-group-item" style="text-decoration: none;"&gt;b/{{ strtolower($post-&gt;subbie) }} · Posted by u/Test&lt;/li&gt;
                          &lt;a href="{!! url()-&gt;current() !!}/s/{{ $post-&gt;subbie }}/{{ $post-&gt;id }}"&gt;
                              &lt;li class="list-group-item mb-3" style="text-decoration: none;"&gt;&lt;h5 class="h5"&gt;Tekst: {{ $post-&gt;body }}&lt;/h5&gt;&lt;/li&gt;
                          &lt;/a&gt;
                      @endforeach
                  &lt;/ul&gt;
              @else
                  &lt;h1&gt;Helaas zijn er nog geen artikels beschikbaar&lt;/h1&gt;
              @endif
          &lt;/div&gt;
      &lt;/div&gt;
  @endsection
  </code></pre>