title: Laravel Excel: CSV to Array
body: <p>So I am working on a form where I want o give the user the option of uploading a CSV that will allow the form to be automatically populated. So I thought I would build a function that reads the CSV and then throws each row into an array as an object which I can then pass back to my Laravel Blade template. My only problem is, the array I return from the function is always empty. Any ideas?</p>
  
  <pre><code>private function import($path) {
      $applicants = [];
  
      Excel::load($path, function(LaravelExcelReader $excel) use ($applicants){
          $excel-&gt;each(function(Collection $line) use ($applicants){      
              $name = new \stdClass;    
  
              $name-&gt;first = $line-&gt;get('first');
              $name-&gt;middle = $line-&gt;get('middle');
              $name-&gt;last = $line-&gt;get('last');
              $name-&gt;birthdate = $line-&gt;get('birthdate');
              $name-&gt;ssn = $line-&gt;get('ssn');
              $name-&gt;email = $line-&gt;get('email');
              $name-&gt;mobile_phone = $line-&gt;get('mobile_phone');
              $name-&gt;home_phone = $line-&gt;get('home_phone');
              $name-&gt;street = $line-&gt;get('street');
              $name-&gt;city = $line-&gt;get('city');
              $name-&gt;state = $line-&gt;get('state');
              $name-&gt;zip = $line-&gt;get('zip');
  
              array_push($applicants, $name);
          });
      });    
  
      return $applicants;
  }
  </code></pre>