title: Get pivot field value for many to many relation in Laravel 5 app
body: <p>I would like to get field value from pivot on many to many relationship in my Laravel 5.4 application.</p>
  
  <p>I have following tables in my MySQL database:</p>
  
  <pre><code>products
   + id
   + name
   + ...
  
  
  nutrients
   + id
   + name
   + ...
  
  products_nutrients
   + product_id
   + nutrient_id
   + value
  </code></pre>
  
  <p><strong><em>products</em></strong> and <strong><em>nutrients</em></strong> tables have its equivalent Eloquent model (<strong><em>Product</em></strong> and <strong><em>Nutrient</em></strong>) with properly working many to many relationship between them.</p>
  
  <p>I need to list all products with values of certain nutrients. I know id of wanted nutrients, so I can set it in query.
  Result should look like collection/array following  of element:</p>
  
  <pre><code>- product name
  - value of nutrient id 1 for product
  - value of nutrient id 2 for product
  - value of nutrient id 3 for product
  </code></pre>
  
  <p>How can I figure it out using Eloquent query builder or in the worst case in raw SQL query? I want to avoid solution with foreach loop.</p>
  
  <p>I am trying to achieve it but without success. I would be glad of any help. Thank you</p>