类照明 support collection的对象无法转换为INT PHP初学者



请给我一些有关我的代码如何正常工作的建议。我有一个循环,可以给我一个ID和数量,以将每个循环更新到我的数据库中。

但是,当我将其传递给我的私人功能并尝试执行它时,我遇到了错误。我只是PHP/Laravel的初学者。这是我的完整代码:

public function updateProduct(Request $request) {
    $ids = array();
        foreach ($request->products as $ship_id) {
            $product_id = DB::table('shipping_products')->select('product_id','quantity')
            ->where(['shipping_products.shipping_id'=>$ship_id])
            ->get();
            array_push($ids,$product_id);
        }
        foreach ($ids as $value) {
            foreach ($value as $update) {
                $this->updateProductQty($update->product_id,$update->quantity);
            }
        }
    }
    private function updateProductQty($product_id, $quantity_order) {
        $qty = DB::table('products')->select('quantity')
            ->where(['products.product_id'=>$product_id])
            ->get();
        $updateTotalQty = $qty - $quantity_order;
        DB::table('products')
            ->where('product_id', $product_id)
            ->update(array(           
            'quantity' => $updateTotalQty
        ));
    }

我在此行中有一个错误:

$this->updateProductQty($update->product_id,$update->quantity);

它说错误消息:

Object of class IlluminateSupportCollection could not be converted to int

尝试这样做以检查数据是否是您要寻找的:

foreach ($ids as $value) {
        foreach ($value as $update) {
            //$this->updateProductQty($update->product_id,$update->quantity);
            var_dump($update);
            var_dump($update->product_id);
            var_dump($update->quantity);
        }
    }