0

I want to add the array value in Session. But it overwrite instead of adding new value.

This is the process of the function.

 public function example(){
    $fileName = $file . "_demo_a.htm";
    $demo["filename"][] = $fileName;
    Session::put($demo);
}

For example , when I run the functino for $file = a , the value is added in Session.But for the next time like $file = b , the value is overwritten.

The result what I want is like this ,

array (
  'filename' => 
  array (
    0 => 'a_demo.htm',
    1 => 'b_demo.htm'
  ),
)  
Yan Myo Aung
  • 398
  • 1
  • 6
  • 18
  • See [Pushing To Array Session Values](https://laravel.com/docs/5.7/session). You should use `push()` instead. – Mozammil Jan 22 '19 at 07:44
  • Thank guys! I got my result after trying Session::push() – Yan Myo Aung Jan 22 '19 at 07:46
  • Quick tip, only use session to store data with page to page requests. If using the session with API development then look for alternative ways to persistent data as sessions will suffer from final write issues when performing multiple concurrent connections for the same session. This means that if you fire multiple requests all at the same time and they all alter some aspect of the session ( can be anything ) then the last connection to complete will trump any changes made by the other sessions due to a session performing a PUT to write back to the session manager and not a PATCH mechanism. – Brendon Moss Jan 22 '19 at 07:52

0 Answers0