mardi 5 mai 2020

How can I update quantity of particular session array data inside foreach loop .in laravel. Here is my code where I want to make changes

$result = Product::where('id','=',$pid)->get(); foreach($result as $val) { $itemArray[$val->product_name] = [ 'id' => $val->id, 'product_name'=>$val->product_name, 'price'=>$val->price, 'qty'=>$qty, 'main_image'=>$val->main_image ];

  if($request->session()->has('cart_item'))
  {

    if(in_array($val->product_name,array_keys($request->session()->get('cart_item'))))
    {

      foreach($request->session()->get('cart_item') as $key=> $vals)
      {

        if($val->product_name == $key)
        {

       // Here i just want to add quantity.. Pls hep


        }
      }
    }
    else{
      $request->session()->put('cart_item',array_merge($request->session()->get('cart_item'),$itemArray));
    }

  }
  else
  {
    $request->session()->put('cart_item', $itemArray);
  }
  }


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire