I want to store in a session array a shopping cart. I'm trying to do this:
class TestController extends Controller
{
function add($id, Request $request) {
if ($request->session()->missing('shopping_cart')) {
$request->session()->put('shopping_cart', []);
}
$item = array(
'id' => $id,
'quntity'=> 1
);
$request->session()->push('shopping_cart', $item);
}
}
Output:
[
0 => [
"id" => "12"
"quantity" => 1
]
]
But when I call another time the function add() it replace the array like so:
[
0 => [
"id" => "20"
"quantity" => 1
]
]
Desired output:
[
0 => [
"id" => "12"
"quantity" => 1
]
1 => [
"id" => "20"
"quantity" => 1
]
2 => [
"id" => "27"
"quantity" => 1
]
]