requiredMapping() ->exampleHeader('Block Name') ->example('Block A') ->label('Block Name') ->rules(['required']), ImportColumn::make('plant') ->requiredMapping() ->exampleHeader('Plant Name') ->example('Ransar Industries-I') ->label('Plant Name') ->relationship(resolveUsing:'name') ->rules(['required']), ]; } public function resolveRecord(): ?Block { $warnMsg = []; $plant = Plant::where('name', $this->data['plant'])->first(); if (!$plant) { $warnMsg[] = "Plant not found"; // $warnMsg[] = "Plant '" . $this->data['plant'] . "' not found"; } if (Str::length($this->data['name']) < 0) { $warnMsg[] = "Block name not found"; } if (!empty($warnMsg)) { throw new RowImportFailedException(implode(', ', $warnMsg)); } return Block::updateOrCreate([ 'name' => $this->data['name'], 'plant_id' => $plant->id ]); // return Block::firstOrNew([ // // Update existing records, matching them by `$this->data['column_name']` // 'email' => $this->data['email'], // ]); // return new Block(); } public static function getCompletedNotificationBody(Import $import): string { $body = 'Your block import has completed and ' . number_format($import->successful_rows) . ' ' . str('row')->plural($import->successful_rows) . ' imported.'; if ($failedRowsCount = $import->getFailedRowsCount()) { $body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to import.'; } return $body; } }