hi there i'm trying to insert data from the cart table to bought table , i should insert multiple records but it only inserts the last value not all , this is my controller function :
public function postIndex(Request $request){
$quantity=$request->input('quantity');
$total_price=$request->input('total_price');
$city=$request->input('city');
$id=$request['product_id'];
$cart=DB::table('cart')->where('id','=',$id)->value('product_id');
$x=DB::table('products')->where('id','=',$cart)->value('quantity');
$user_id=Auth::user()->id;
if($x < $quantity) {
return redirect('cart');
}elseif ($x >= $quantity) {
$data =array(array('quantity' =>$quantity ,'total_price'=>$total_price ,'city'=>$city,'product_id'=>$cart,'user_id'=>$user_id));
DB::table('bought')->insert($data);
$product=DB::table('products')->where('id','=',$cart)->value('quantity');
$query= $product - $quantity ;
DB::table('products')->where('id','=',$cart)->update(['quantity'=>$query]);
return redirect()->action('followController@getIndex');
}
ccan anyone help me knowing what is the error ?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire