title: Laravel Eloquent distinct not working as intended
body: <p>I'm currently creating a basic private messaging system in Laravel. In my database I have a messages table. Two of the columns are "sender_id" and "recipient_id". </p>
  
  <p>What I am trying to do is use eloquent to go through this table and list in the inbox all the times the current logged in user's id is listed in these columns. I will then use "distinct" to ignore duplicate entries so that the user is only listed once. Using this ID, I can display the username of the recipient so that when the user clicks on the username, it will take them to the message thread for that user. </p>
  
  <p>For the sake of testing, I am only currently retrieving the column "recipient_id" and outputting it into the blade. Here is the line I believe should only output the recipient once despite being found many times in the table. </p>
  
  <p><strong>MessageController</strong></p>
  
  <pre><code>$messages = Message::where('recipient_id', $user)-&gt;distinct('recipient_id')-&gt;get();
  </code></pre>
  
  <p>However in the blade, the same user is being output twice (as they have 2 messages found) when I would have expected the distinct function to remove the duplicate entry. </p>
  
  <p>I have also tried</p>
  
  <pre><code>$messages = Message::where('recipient_id', $user)-&gt;distinct()-&gt;get();
  </code></pre>
  
  <p>But that also did not work. </p>
  
  <p>If I have received 3 messages from 2 different users, it is outputting something like below:</p>
  
  <p>Messages from:</p>
  
  <ul>
  <li>Example User 1</li>
  <li>Example User 1</li>
  <li>Example User 2</li>
  </ul>
  
  <p>What it should output</p>
  
  <ul>
  <li>Example User</li>
  <li>Example User 2</li>
  </ul>
  
  <p>Thanks</p>