/** * Execute the console command. * * @return mixed */ public function handle() { // read file $csv = Reader::createFromPath(storage_path($this->argument('file'))); //get the first row, usually the CSV header $this->headers = collect($csv->fetchOne()); // grab all rows $rows = $csv->setOffset(1)->fetchAll(); // remove the last row if null if (!$rows[count($rows) - 1][0]) { array_pop($rows); } // loop them foreach ($rows as $row) { // map $school = School::firstOrNew(['name' => $row[$this->column('SchoolName')]]); $this->mapData($school, $row); // save if ($this->changes($school)) { $school->save(); } $this->processed++; } $this->comment('Finished Schools Bulk Update'); $this->comment('Processed: ' . $this->processed); $this->comment('Changed: ' . $this->changes); }