在laravel 5.2中插入输入数组


Insert input array in laravel 5.2

我有问题,我想在数据库中插入输入数组,但只插入数据库中的一行,我不能插入超过一行。

public function checkout(Request $request){
            $input= $request->all();
            $pay = new Pays;
            $bill= new detail_bills;
            $id_buy= $request->get('post_id');
            $name_product= $request->get('name_session');
            $picture= $request->get('picture');
            $quantity= $request->get('qty');
            $price= $request->get('price');
            foreach (Session::get('product') as $key =>$value)
            {
               $item = array([
                           "id_buy"       => $id_buy[$key],
                           "name_product" => $name_product[$key], 
                           "picture"      => $picture[$key], 
                           "price"        => $price[$key], 
                           "quantity"     => $quantity[$key]
                ]);

            }
            DB::table('detail_bills')->insert($item );
}

试试这个代码:

        //...
        foreach (Session::get('product') as $key =>$value)
        {
           $item = array([
                       "id_buy"       => $id_buy[$key],
                       "name_product" => $name_product[$key], 
                       "picture"      => $picture[$key], 
                       "price"        => $price[$key], 
                       "quantity"     => $quantity[$key]
            ]);
        // move here
        DB::table('detail_bills')->insert($item );

        }

 }