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!
I suppose it can be something like:
// set products.name as array
session()->put('products.name', []);
// somewhere later
session()->push('products.name', $name1);
// somewhere else later
session()->push('products.name', $name2);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With