Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/251.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在laravel 5.2中插入输入数组_Php_Laravel - Fatal编程技术网

Php 在laravel 5.2中插入输入数组

Php 在laravel 5.2中插入输入数组,php,laravel,Php,Laravel,我有问题,我想在数据库中插入输入数组,但只在数据库中插入一行,我不能插入超过一行 public function checkout(Request $request){ $input= $request->all(); $pay = new Pays; $bill= new detail_bills; $id_buy= $request->get('post_id');

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

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


        }


 }