rows = $rows; } public function handle(): void { $artists = collect(); foreach ($this->rows as $index => $row) { try { $name = trim($row['歌手姓名'] ?? ''); if (empty($name) || Artist::where('name', $name)->exists()) { continue; } $artist = new Artist([ 'name' => $name, 'category' => ArtistCategory::tryFrom(trim($row['歌手分類'] ?? '未定義')) ?? ArtistCategory::Unset, 'enable' => trim($row['狀態'] ?? 1), ]); $artists->push($artist); } catch (\Throwable $e) { \Log::error("Row {$index} failed: {$e->getMessage()}", [ 'row' => $row, 'trace' => $e->getTraceAsString() ]); } } $artists->each(fn ($artist) => $artist->save()); } }