[英]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.