title: Split one function into two
body: <p>for the reusability, I plan to split my function into two functions. Basically, the concept of the function is loads the input file then preview the data. </p>
  
  <p>Working Code</p>
  
  <pre><code>public function uploadImportCsv()
      {
          $file = Input::file('file');
          $extension = $file-&gt;getClientOriginalExtension();
          $filename = sha1($file-&gt;getClientOriginalName().time()) . ".{$extension}";
          //upload to s3
          #doing upload to s3
  
          $data = [
              'title'=&gt;[],
              'value'=&gt;[]
              ];
      $results = Excel::load(Input::file('file'), function($reader){
  
              })-&gt;get();
      foreach ($results as $result) {
          foreach ($result as $key =&gt; $value) {
              if(!in_array($key, $data['title'])){
                  array_push($data['title'], $key);
              }       
          }
          array_push($data['value'], $result);
      }
  
          return Response::json(['filename' =&gt; $filename, 'data' =&gt; $data]);
      }
  </code></pre>
  
  <p>after split</p>
  
  <pre><code>public function previewCsv()
      {
          //Preview table
          $data = [
                  'title'=&gt;[],
                  'value'=&gt;[]
                  ];
          $results = Excel::load(Input::file('file'), function($reader){
  
                  })-&gt;get();
          foreach ($results as $result) {
              foreach ($result as $key =&gt; $value) {
                  if(!in_array($key, $data['title'])){
                      array_push($data['title'], $key);
                  }       
              }
              array_push($data['value'], $result);
          }
          return Response::json(['data' =&gt; $data]);
      }
  
      public function uploadImportCsv()
      {
          $file = Input::file('file');
          $extension = $file-&gt;getClientOriginalExtension();
          $filename = sha1($file-&gt;getClientOriginalName().time()) . ".{$extension}";
          //upload to s3
          #doing upload to s3
  
          $data = $this-&gt;previewCsv();
  
  
          return Response::json(['filename' =&gt; $filename,'data' =&gt; $data]);
      }
  </code></pre>
  
  <p>I called the function from the preview function but it does not work.</p>