mercredi 12 septembre 2018

how to add new array to an global session array in laravel?

I want to add new arrays to an global session array in laravel 5.6

The global session is cart. I want add items to this array.

I try this:

for first time:

$item = ['key' => 'val1'];

session()->push('cart', $item);
dd(session()->get('cart'));

It works:

array:1 [▼
  0 => array:1 [▼
    "key" => "val1"
  ]
]

Now, I change $item = ['key' => 'val1']; to $item = ['key' => 'val2']; and refresh the page again.

but it remove "key" => "val1" and return this:

array:1 [▼
      0 => array:1 [▼
        "key" => "val2"
      ]
    ]

what's my wrong?



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2OdCKfP
via IFTTT

Aucun commentaire:

Enregistrer un commentaire