1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

how to add new array to an global session array in laravel?

Discussion in 'Programming/Internet' started by Areza, Sep 12, 2018.

  1. Areza

    Areza Guest

    I want to add new arrays to an global session array in laravel 5.6

    The global session is cart. I want add items to this array.

    I try this:

    for first time:

    $item = ['key' => 'val1'];

    session()->push('cart', $item);
    dd(session()->get('cart'));


    It works:

    array:1 [▼
    0 => array:1 [▼
    "key" => "val1"
    ]
    ]


    Now, I change $item = ['key' => 'val1']; to $item = ['key' => 'val2']; and refresh the page again.

    but it remove "key" => "val1" and return this:

    array:1 [▼
    0 => array:1 [▼
    "key" => "val2"
    ]
    ]


    what's my wrong?

    Login To add answer/comment
     

Share This Page