title: Laravel 4 : How to get selected/specific columns in a many to many relationship?
body: <p>I want to get all users that is related to a certain conversation. The pivot table has <code>user_id</code> and <code>conversation_id</code> columns. <code>user_id</code> and <code>conversation_id</code> references the <code>id</code> column on user and conversations table respectively. </p>
  
  <p>So I did :</p>
  
  <pre><code>Conversations::find($conv_id)-&gt;users()
  </code></pre>
  
  <p>This is ok but it returns all the details of the related user. Based on the code above, how do I return only certain columns of the user such as <code>id</code> and <code>name</code>?</p>
  
  <p>P.s. Additionally, I know I can do this by creating a modal for pivot table but it seems like an overkill. Is it a good practice to create a modal for pivot table?</p>
  
  <p><strong>I have tried</strong></p>
  
  <pre><code>Conversations::select('id','name')-&gt;find($conv_id)-&gt;users()-&gt;get()-&gt;toArray();
  </code></pre>
  
  <p>but the result is still the same.</p>
  
  <p><strong>I have also tried</strong></p>
  
  <pre><code>Conversations::find($conv_id)-&gt;users()-&gt;get(array('id','name'))-&gt;toArray();
  </code></pre>
  
  <p>but it gives the error : </p>
  
  <pre><code>SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'id' in field list is ambiguous.. 
  </code></pre>
  
  <p>Thank you for your time.</p>