csvImporter = $csvImporter; } public function handle(): void { $rows = $this->csvImporter->readCsv(storage_path('app/import/import.csv')); $checkedSchools = collect(); foreach ($rows as $row) { if ($checkedSchools->contains($row['School'])) { continue; } $checkedSchools->push($row['School']); if (School::where('name', $row['School'])->count() > 0) { $this->info('School '.$row['School'].' already exists'); } else { $this->newLine(); $this->alert('School '.$row['School'].' does not exist'.PHP_EOL.'Creating school...'); School::create(['name' => $row['School']]); $this->info('School '.$row['School'].' created'); } } } }