简体   繁体   English

无法将Illuminate \\ Support \\ Collection类的对象转换为int php初学者

[英]Object of class Illuminate\Support\Collection could not be converted to int php beginner

please give me some suggestions on how my code will work properly. 请给我一些有关我的代码如何正常工作的建议。 I am having a loop that gives me an id and quantity to update every loop into my database. 我有一个循环,为我提供了ID和数量以更新数据库中的每个循环。

but i got an error when i pass it to my private function and try to execute it. 但是当我将其传递给我的私有函数并尝试执行它时出现错误。 I am just a beginner in PHP/Laravel. 我只是PHP / Laravel的初学者。 Here is my full code: 这是我的完整代码:

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

    }

i got an error in this lines: 我在这行中有一个错误:

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

it says error message: 它显示错误消息:

Object of class Illuminate\Support\Collection could not be converted to int

Try to do that to check if the data is what you're looking for: 尝试执行此操作以检查数据是否在寻找中:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Illuminate \\ Support \\ Collection类的对象无法转换为int -laravel - Object of class Illuminate\Support\Collection could not be converted to int -laravel 如何修复 class 的 Object Illuminate\Support\Collection 无法转换为 int? - how to fix Object of class Illuminate\Support\Collection could not be converted to int? 无法使用json_encode()将Illuminate \\ Support \\ Collection类的对象转换为int - Object of class Illuminate\Support\Collection could not be converted to int with json_encode() 无法将Illuminate \\ Database \\ Eloquent \\ Collection类的对象转换为int - Object of class Illuminate\Database\Eloquent\Collection could not be converted to int Illuminate \\ Database \\ Eloquent \\ Collection类的对象无法转换为int Laravel 5.4 - Object of class Illuminate\Database\Eloquent\Collection could not be converted to int Laravel 5.4 无法将Illuminate \\ Validation \\ Rules \\ Unique类的对象转换为int - Object of class Illuminate\Validation\Rules\Unique could not be converted to int Object 的 class Illuminate\Pagination\LengthAwarePaginator 无法转换为 int - Object of class Illuminate\Pagination\LengthAwarePaginator could not be converted to int Object 的 class Illuminate\Routing\Redirector 无法转换为 int laravel - Object of class Illuminate\Routing\Redirector could not be converted to int laravel 类 Illuminate\\Routing\\Route 的对象无法转换为 int - Object of class Illuminate\Routing\Route could not be converted to int Object 的 class Illuminate\Http\Response 无法转换为 int - Object of class Illuminate\Http\Response could not be converted to int
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM