1

I have problem, i want to insert input array in database but just insert 1 row in database i can't insert more than 1 row.

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

1 Answer 1

2

try this code :

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


        }


 }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.