samedi 28 avril 2018

Laravel eloquent: Multiply two columns of two different tables and display

Carts table columns :

    'id',
    'user_id',
    'sp_id',
    'service_id',
    'dryclean',
    'q_Shirt',
    'q_Pant',
    'q_Tie'

Pricing table column :

'id'
'sp_id'
'Shirt'
'Pant'
'Tie'

Both table do not have any relationship defined.

In cart controller

public function cart($sp_id, $service_id)
    {
     $prices = DB::table('pricings')->where('pricings.sp_id', '=', $sp_id)->get();
     $cart = DB::table('carts')->where('carts.service_id', '=' , $service_id)->where('carts.sp_id','=', $sp_id)->where('user_id', '=' , auth()->id())->orderBy('id', 'desc')->take(1)->get();
     return view('user.cart')->with('prices', $prices)->with('cart', $cart);
    }

How do I calculate total amount of order?

If column dryclean has value of none then total is 0. else total will be

(
carts->q_Shirt*prices->Shirt +
carts->q_Pant*prices->Pant +
carts->q_Tie*prices->Tie
) 

This code is just for understanding of how I am calculating total

Please help me write code in laravel controller to calculate total and how to display it in view.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2r7vjMR
via IFTTT

Aucun commentaire:

Enregistrer un commentaire