jeudi 13 juin 2019

How can I retrieve the current product id from database?

I'm trying to get product id, so I can save to order_product table. But I'm stuck.

Here is my store function in checkout Controller

//Insert into order product table
if ($order) {
    foreach(session('cart')  as $item) {
        if (empty($item)) {
            continue;
        }

        OrderProduct::create([
            'order_id' => $order->id ?? null,
            'product_id' =>DB::table('products')->get('id'),
           // $products=DB::table('products')->where('id',$id)->get();
            'quantity' => $item['quantity'],
        ]);
   }
}

I need to be able to save current product_id associated with the order in the database. Because right now it shows

Incorrect integer value: '[{"id":1},{"id":2}]' for column 'product_id'

Any help will be appreciated.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire