title: Get sum of multiplication of two column values from unrelated tables in cart
body: <p>In my laravel ecommerce project 
  I have 2 tables in the database :   </p>
  
  <pre><code> cart [c_id(pk), laundry, l1, dryclean, dc1, dc2, dc3, shop_id]
   price [p_id, p_l1, p_dc1, p_dc2, p_dc3, shop_id]
  </code></pre>
  
  <p>In controller I get prices of logged in shop i.e. single row</p>
  
  <pre><code>$price = DB::table('price')-&gt;where('price.shop_id', '=', auth()-&gt;id())-&gt;get();
  </code></pre>
  
  <p>also to get a row from cart table I am taking the most recent entry</p>
  
  <pre><code>$cart = DB::table('cart')-&gt;latest()-&gt;first();
  </code></pre>
  
  <p>Laundry and dryclean columns from cart table can have two values YES and NO. If laundry is yes then user also enters l1(which is quantity) else null.</p>
  
  <p>similarly, for dryclean column can have two values YES and NO. If YES then user also enters dc1, dc2, dc3(quantities of items).</p>
  
  <p>Now I want to get the Total amount on checkout page from controller including conditions where values of laundry and dryclean are checked.</p>
  
  <p>So far I was calculating total in the view file. </p>
  
  <pre><code>@if ( $cart-&gt;dryclean == "no")
      @php $c1=0;$c2=0;$c3=0; @endphp
  @else
        @if (is_null($cart-&gt;dc1))
        @php  $c1=0; @endphp
        @else
              @php
              $a1= $cart-&gt;dc1;
              $b1 =$price-&gt;p_dc1;
              $c1= $a1*$b1;
              @endphp
        @endif
        @if (is_null($cart-&gt;dc2))
        @php  $c2=0; @endphp
        @else
              @php
              $a2= $cart-&gt;dc2;
              $b2 =$price-&gt;p_dc2;
              $c2= $a2*$b2;
              @endphp
        @endif
        @if (is_null($cart-&gt;dc3))
        @php  $c3=0; @endphp
        @else
              @php
              $a3= $cart-&gt;dc3;
              $b3 =$price-&gt;p_dc3;
              $c3= $a3*$b3;
              @endphp
        @endif
  
        {{ $c1 + $c2 + $c3}}   &lt;!-- This is total amount --&gt;
        @endif
  </code></pre>
  
  <p>Please help me writing controller queries to calculate total amount in controller itself and display in the view. </p>
  
  <p>Thanks in advance.</p>