I was trying to store some data in session through ajax. Means from Ajax request i would get the product_id and it put it inside product array through Session. And I want to retrieve every session array data.
Every Ajax request product_id will be stored into Session Array:
// for storing $products into session following controller .But it stored only last one not the previous request
public function postEnquote(Request $request)
{
$product = Product::where('id',$request->Input(['product_id']))->first();
Session::put('product', $product);
}
// For retrieving every session data i used following one, but doesn't work properly means i couldn't get every session data..
public function enquoteList()
{
foreach(Session::get('product') as $test)
{
var_dump($test->id);
}
}
$_SESSIONsuperglobal directly?Session::put('product', $product);- you're overwriting this every time, not appending it. If you want multiple products, then you'll have to store it as an array within the session.$_SESSIONhard-coded like that it'd be a pain to change it all across the app.