public function processFacilityFile()
 {
     ini_set('max_execution_time', 300);
     $filePath = storage_path('exports') . '/eHealthKenyaFacilities.xlsx';
     \Excel::load($filePath, function ($reader) {
         $provinces = [];
         $counties = [];
         $subcounties = [];
         $facilities = [];
         $results = $reader->get();
         foreach ($results as $sheet) {
             foreach ($sheet as $row) {
                 $mfl = $row->facility_code;
                 $fname = $row->facility_name;
                 $province = $row->province;
                 $county = $row->county;
                 $subcounty = $row->district;
                 $facilityarr = ['mfl' => $mfl, 'facilityname' => $fname, 'subcounty' => $subcounty];
                 $subcountyarr = ['subcounty' => $subcounty, 'county' => $county];
                 if (!in_array($county, $counties)) {
                     $counties[] = $county;
                 }
                 if (!in_array($subcountyarr, $subcounties)) {
                     $subcounties[] = $subcountyarr;
                 }
                 if (!in_array($facilityarr, $facilities)) {
                     $facilities[] = $facilityarr;
                 }
             }
         }
         //insert counties
         //alter table county auto_increment=1;
         foreach ($counties as $county) {
             $countyModel = new County();
             $countyModel->name = $county;
             $countyModel->save();
         }
         $dbCounties = County::all();
         foreach ($subcounties as $sc) {
             $scname = $sc['subcounty'];
             $countyName = $sc['county'];
             $countyId = 0;
             foreach ($dbCounties as $dbs) {
                 if ($countyName == $dbs->name) {
                     $countyId = $dbs->id;
                     break;
                 }
                 //echo $dbs->id.' '. $dbs->name.'<br/>';
             }
             $newSubCounty = new SubCounty();
             $newSubCounty->name = $scname;
             $newSubCounty->county_id = $countyId;
             $newSubCounty->save();
         }
         $dbSubCounties = SubCounty::all();
         $facilityarr = ['mfl' => $mfl, 'facilityname' => $fname, 'subcounty' => $subcounty];
         foreach ($facilities as $f) {
             $mfl = $f['mfl'];
             $fname = $f['facilityname'];
             $scName = $f['subcounty'];
             $scountyId = 0;
             foreach ($dbSubCounties as $dbsc) {
                 if ($scName == $dbsc->name) {
                     $scountyId = $dbsc->id;
                     break;
                 }
             }
             $newFacility = new Facility();
             $newFacility->mfl_code = $mfl;
             $newFacility->subcounty_id = $scountyId;
             $newFacility->name = $fname;
             $newFacility->save();
         }
     });
     Session::flash('success', 'uploaded file is not valid');
     return redirect('/facility-upload');
 }