title: How to update session array in laravel 4 - updated with new items
body: <p>I'm using ajax and laravel 4 and I upload files that are arrays - they are multiple. But I'm not sure how to update session array withe the new array. I've tried array_merge but it's overwrited.</p>
  
  <p>My method looks like that:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>public function storeFiles() {
    $name = Input::get('name');
    $input = Input::all();
    $current_time = time();
  
    $trim_name = trim($name, '[]');
    $corporate_docs = array();
  
    foreach ($input[$trim_name] as $corporate) {
        $file_name = $current_time . '_' . $corporate-&gt;getClientOriginalName();
  
        $corporate-&gt;move(APPLICATIONS_DIR, $file_name);
        $corporate_docs[] = $file_name;
     
    }  
    $session = Session::get($name);
    if($session) {
      $docs = array_push($session, $corporate_docs); 
      Session::put($name, $docs); 
    } else {
      Session::put($name, $corporate_docs);
    }
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>How should I merge existing session array withe the newly created?</p>
  
  <p>Updated: my code now is:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code> $trim_name = trim($name, '[]');
                  $corporate_docs = array();
  
                  foreach ($input[$trim_name] as $corporate) {
                      if ($corporate) {
                          $file_name = $current_time . '_' . $corporate-&gt;getClientOriginalName();
                  
                          $corporate-&gt;move(APPLICATIONS_DIR, $file_name);
                          $corporate_docs[] = $file_name;
                          
                      }
                  }
                  $session = Session::get($name);
                  if (Session::has($name)) {
                       $docs = array_merge($session, $corporate_docs); //dd($docs);
                       Session::forget($name);
                       Session::put($name, $docs); dd(Session::get($name));
                  } else {
                      Session::put($name, $corporate_docs);
                  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>But it is everwwriten again. When I add first image, it is stored in session and when I add another, it is merged with the first array but when I add third image, in the newly created session array - it is first image and last image. Second image is overwriten.</p>