EMfinanga
1 year ago
177
2
Laravel

Loop multiple select data

Posted 1 year ago by EMfinanga

i have a invoice which perform sales basis, , so i want to select product_id and store name(office or Yard) then to calculate some some formular as per code below.

but right now it select only one row and perform calculation, i want to select multiple row according then perform calculation.

below is my code.

           for ($a=0; $a < count($ids); $a++)
    {
        //create detail on data 

        $ido=$request->name[$a];
        $store=$request->store[$a];

        $model=([
            'invoice_no'=>$fk, 
            'customer_id'=>$request->customer_id, 
             'name'=>$request->name[$a],
            'store'=>$request->store[$a],
            'selling_price'=>$request->selling_price[$a], 
            'amount'=>$request->amount[$a],
            'qty'=>$request->qty[$a], 
        ]);
        //update stok
         $data=Stock::select('quantity')->where([
                        ['id', '=', $ido],
                        ['store', '=', $store],
                          ])->first();
        //$data=Stock::select('quantity')->where('id','=',$ido)->first();
  
        $stokl=(int)$data->quantity-(int)$request->qty[$a];

        dd($stokl);
        
        $model1=([
            'quantity'=>$stokl,

        ]);
        $x=Stock::find($ido);

        if($x->update($model1))
        {
            Sales::create($model);
        }

when i running dd($stokl); is show the calculation of one row, while i entered two rows

Please sign in or create an account to participate in this conversation.