Search
 
SCRIPT & CODE EXAMPLE
 

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);
}
Comment

PREVIOUS NEXT
Code Example
Php :: Passing values to blade using redirect() and back() functions 
Php :: php slice string by character 
Php :: laravel route regex except 
Php :: tenary php 
Php :: wp wordPress variables de session 
Php :: add filter in wordpress 
Php :: laravel automatically encrypt model atribute 
Php :: pagination using ajax 
Php :: bool value of blank string inp php 
Php :: numbers not displaying in laravel pagination 
Php :: php unit test 
Php :: prevent xss attack in laravel 
Php :: php readlink 
Php :: symfony twig variable 
Php :: test_input php 
Php :: mage log equivalent magento 2 
Php :: adding two numbers in php 
Php :: create middleware laravel 
Php :: scss laravel 
Php :: php arrays 
Php :: laravel blade for if 
Php :: laravel package console command 
Php :: whats the difference between using date function and DATETime in php 
Php :: Laravel - multiple select query 
Php :: php page sends cookie to visitor 
Php :: laravel request query logger 
Php :: php var_dump() 
Php :: how convert the string to int in laravel function event 
Php :: how to convert amount in words in php 
Php :: enableQueryLog 
ADD CONTENT
Topic
Content
Source link
Name
6+5 =