Reputation: 2505
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);
}
}
Upvotes: 0
Views: 7069
Reputation: 13562
Use push
to add a value to an array
public function postEnquote(Request $request)
{
$product = Product::where('id',$request->Input(['product_id']))->first();
Session::push('product', $product);
}
Upvotes: 0
Reputation: 2365
You will have to use push
here.
Session::push('product', $product);
So all new $product
push into 'product'
session variable.
Upvotes: 4