I've created this online shopping cart, if a buyer buys with one checkout item, works well, but there is a problem when the buyer is shopping with multiple items, not working properly.
I need help, so that the items from the shopping cart can be put all into the database. My problem is inserting multiple products from the shopping cart into the database as individual rows. Can anyone help?
I want this because the items that have been purchased can be reviewed by the buyer who bought the item. so i can get "product_id".
Table: orders
Columns:
id int(10) UN AI PK
user_id int(11)
product_id int(11)
item_name text
payment varchar(255)
courier varchar(255)
note text
quantity int(11)
total int(11)
status int(11)
OrderController.php
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->product_id = $data['id'];
$new->item_name = $data['item_name'];
$new->payment = $request['payment'];
$new->courier = $request['courier'];
$new->note = $request['note'];
$new->quantity = $quantity;
$new->total = $total_harga;
$new->status = 1;
$new->save();
$id = $new->id;
Session::forget('cart');
return redirect()->route('order.status', $id);
}
how to inserting multiple products from the shopping cart into the database as individual rows?
Thanks for the answer :)
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2hRsyuZ
via IFTTT
Aucun commentaire:
Enregistrer un commentaire