title: Laravel get users by id in user model and store them in an array
body: <p>I'm trying to make a simple "friends" system, by storing each friend id in a single column as a string separated with a comma.</p>
  
  <p>I want to get the users by id and store them in an array:</p>
  
  <pre><code>public function getFriends() {
      $friendids = explode(',', $this-&gt;friends);
      $friends = [];
  
      foreach ($friendids as $id) {
          $friends[] = User::findOrFail($id);
      }
  
      return $friends;
  }
  </code></pre>
  
  <p>So I can do this in my view:</p>
  
  <pre><code>@foreach ($user-&gt;getFriends() as $friend)
      &lt;p&gt;Friend ID: {{ $friend-&gt;id }}&lt;/p&gt;
      &lt;p&gt;Friend Username: {{ $friend-&gt;username }}&lt;/p&gt;
  @endforeach
  </code></pre>
  
  <p>But I think I can't use findOrFail in the user model or what am I doing wrong?</p>