Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
766 views
in Technique[技术] by (71.8m points)

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

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 IlluminateDatabaseQueryBuilder 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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...