title: How to pluck a value from foreach statement in Laravel
body: <p>I am getting an array from database table and through a for each statement. Then check the difference between two values if there is any difference that is less than zero sets a value to 0 for that loop. Then do the same with the next loop.</p>
  
  <pre class="lang-php prettyprint-override"><code>$bom_id = App\Models\Bom::where('item_id', $item-&gt;order_item-&gt;id)-&gt;pluck('id')-&gt;first();
  if ($bom_id &gt; 0) {
      $bomList = App\Models\Bom_list::where('bom_id', $bom_id)-&gt;get();
      echo '&lt;div class="row"&gt;';
  
      foreach ($bomList as $bomlist) {
          $availableQty = $item-&gt;order_item-&gt;qty;
          $requiredQty = $bomlist-&gt;qty * $item-&gt;qty;
          $dif = $availableQty - $requiredQty;
      }
  
      $check = '';
      $arr = array($bomlist-&gt;$dif);
      $light = in_array($check, $arr, true) ? 0 : 1;
  } else {
      $light = 0;
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/LSOLB.png" rel="nofollow noreferrer">enter image description here</a></p>