how can loop all data then save it after check all data in loop

北城余情 提交于 2019-12-11 14:57:14

问题


Now query is already work but if I add multiple id_p it's checking only first loop any idea how to fix this I want to check all id_p $available > 1 then save(); into database

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

the error said: Object of class Illuminate\Database\Query\Builder could not be converted to int

here is my data in v_total_quantiy table

    id_w | id_p  | product_name| total_quantity_box
    10   | 1     | snack       |10
    10   | 2     | watebottle  |10   
    10   | 3     | headphone   |10

来源:https://stackoverflow.com/questions/46502971/how-can-loop-all-data-then-save-it-after-check-all-data-in-loop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!