Wednesday, March 8, 2017

How to push an array to an existing session in laravel

Prior to my previous question I have come up with another idea to push array of items in a single session

For instance I have a session session('products')

Now what I have, are sets of items for instance.

Name=Item1
Class=Good

Name=Item2
Class=Bad

Name=Item3
Class=Good

Name=Item4
Class=Bad

I learnt that

session()->put('products.name', $name);
session()->put('products.class', $class);

This would simply put items to it but When I try to put another array to session, it just replaces the values,

Thus I tried to use push() method

session()->push('products.name', $name);
session()->push('products.class', $class);

But it shows that [] operator not supported for strings Does anyone have solution to this?

I am new to laravel and learning!



via Alen

Advertisement