现在查询已经有效但是如果我添加多个id_p它只检查第一个循环任何想法如何解决这个我想检查所有id_p $ available> 1然后保存();进入数据库
$count = count($request->get('quantity_box'));
for ($i=0; $i < $count; $i++) {
$available = $this->check_stock($id_w, $id_p, $qty);
$id_w = $request->input('idw');
$id_p = $request->get('id_p')[$i];
if($available > 0){
echo 'success';
}else{
echo 'error';
}
}
private function check_stock($idw, $id_p,$qty){
$count = DB::table('v_total_quantity')
->select([
'total_quantity_box',
])
->where('v_total_quantity.id_w',$idw)
->where('v_total_quantity.id_p',$id_p)
->where('v_total_quantity.total_quantity_box','>',$qty)
->count();
return $count;
}
错误说:类Illuminate \ Database \ Query \ Builder的对象无法转换为int
这是我在v_total_quantiy表中的数据
id_w | id_p | product_name| total_quantity_box
10 | 1 | snack |10
10 | 2 | watebottle |10
10 | 3 | headphone |10