title: Sum in Laravel Eloquent and Return on Page
body: <p>I'm trying to get the location's inventory value with the following eloquent query. It properly pulls up everything (location name, address, # of users, etc) except the inventory value which returns null. I first built this query in SQL which works great but for whatever reason doesn't work in eloquent. It was the same exact query.</p>
  
  <pre><code>$locations = \App\Models\Location::select(DB::raw('locations.*', 'SUM(inventory.part_price * inventory.quantity) AS inventory_value'))
              -&gt;leftJoin('inventory', 'locations.id', '=', 'inventory.location_id')
              -&gt;where('locations.company_id', '=', Auth::user()-&gt;company_id)
              -&gt;groupBy('locations.id')
              -&gt;get();
  </code></pre>
  
  <p>On the blade file, I'm using a <code>@foreach</code> loop. I try using <code>{{$location-&gt;inventory_value}}</code> which returns null. I've tried to dump that particular variable in the controller and it is null there too. The blade file looks like this:</p>
  
  <p><a href="https://i.stack.imgur.com/X9wUZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/X9wUZ.png" alt="enter image description here"></a></p>
  
  <p>It should be returning the inventory value of all of the following:</p>
  
  <p><a href="https://i.stack.imgur.com/NIJJP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NIJJP.png" alt="enter image description here"></a></p>
  
  <p>Ultimately my question is how do I fix this query to get the sum of the inventory price and quantity to show on the blade file? Thanks!</p>