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?
private function import($path) {
$applicants = [];
Excel::load($path, function(LaravelExcelReader $excel) use ($applicants){
$excel->each(function(Collection $line) use ($applicants){
$name = new \stdClass;
$name->first = $line->get('first');
$name->middle = $line->get('middle');
$name->last = $line->get('last');
$name->birthdate = $line->get('birthdate');
$name->ssn = $line->get('ssn');
$name->email = $line->get('email');
$name->mobile_phone = $line->get('mobile_phone');
$name->home_phone = $line->get('home_phone');
$name->street = $line->get('street');
$name->city = $line->get('city');
$name->state = $line->get('state');
$name->zip = $line->get('zip');
array_push($applicants, $name);
});
});
return $applicants;
}