Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

find total value from cart in laravel

public function NewOrder(Request $request)
{
$this->validate($request, [
    'payment' => 'required',
    'courier' => 'required',
]);
$cart = Session::get('cart');
$total = 0;
foreach ($cart as $data) {
    $total_harga = $data['harga'] * $data['qty'];
    $qty = $data['qty'];
}
$quantity = $qty + 0;

$new = new Orders();
$new->user_id = Auth::user()->id;
$new->payment = $request['payment'];
$new->courier = $request['courier'];
$new->note = $request['note'];
$new->total_quantity = $quantity;
$new->total_amount = $total_harga;
$new->status = 1;
$new->save();

$order_id = DB::getPdo()->lastInsertId();

foreach ($cart as $data) {
    $total_harga = $data['harga'] * $data['qty'];
    $qty = $data['qty'];
    $OrderPro = new Ordersproducts;
    $OrderPro->order_id = $order_id;
    $OrderPro->product_id = $data['product_id'];
    $OrderPro->product_name = $data['product_name'];
    $OrderPro->product_price = $data['product_price'];
    $OrderPro->product_quantity = $data['product_quantity'];
    $OrderPro->save();
}

Session::forget('cart');
return redirect()->route('order.status', $id);
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #find #total #cart #laravel
ADD COMMENT
Topic
Name
1+6 =