在那里我试图将数据从购物车表插入到买表中,我应该插入多条记录,但它只插入最后一个值而不是全部,这是我的控制器功能:
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');
}
谁能帮助我知道什么是错误?