title: Laravel - how to make nested users unique
body: <p>before I will start really hating php and laravel, I'll ask for help</p>
  
  <p>I'm trying to make unique values of users that are part of my offer collection. </p>
  
  <p>This collection is done by relation on users model:</p>
  
  
  
  <pre class="lang-php prettyprint-override"><code>public function users(){
      return $this-&gt;belongsToMany(User::class, 'messages', 'offer_id', 'from');
  }
  </code></pre>
  
  <p>And in controller:</p>
  
  <pre class="lang-php prettyprint-override"><code>    $user_id = auth()-&gt;user()-&gt;id;
      $offers = Offer::where('user_id', $user_id)-&gt;orderBy('created_at','desc')-&gt;get();
      foreach ($offers as $offer)
      {
          $offer-&gt;users;
      }
      return $offers;
  </code></pre>
  
  <p>This is somehow (?) giving me right result with nested 'users' inside my offer collection. </p>
  
  <p>offer_title
  :
  (...)</p>
  
  <p>users
  :
  Array(3)
  0
  :
  {…}
  1
  :
  {…}
  2
  :
  {…}</p>
  
  <p>And this is correct result, except - users are duplicating - because one user can send multiple messages. This is why I'm trying to make them unique this way:</p>
  
  <pre class="lang-php prettyprint-override"><code>    foreach ($offers as $offer)
      {
          $offer-&gt;users = $offer-&gt;users-&gt;unique()-&gt;values()-&gt;all();
      }
      return $offers;
  </code></pre>
  
  <p>but this is not working at all. I've tried many configurations. How can I fix it?</p>