jeudi 7 novembre 2019

How to update item in session array in laravel

I need update 1 item of my session , i send a new quantity from my form, $item['quantity'] change but not Session::get('details_evacuation_file')

It's the structure

Session::push('details_evacuation_file', [
              'id' => $p_temp->id,
              'quantity' => 1,
              'cost' => null,
              'discount' => 0,
              'product' => $p_temp  
            ]);

My function

public function update_quantity(Request $request) {
       $details = Session::get('details_evacuation_file', []);
        foreach ($details as $item) {
            if ($item['id'] == $request->input('id')) {
                var_dump($item['quantity']); 
                $item['quantity'] = $request->input('quantity');
                var_dump($request->input('quantity')); 
                var_dump($item['quantity']);  
            }
        }
       session('details_evacuation_file', $details );
       var_dump(Session::get('details_evacuation_file'));
       die();
       return redirect()->back();
    }


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire