You’re on the right track by wanting to exclude the generated ID from the CSV and instead set it programmatically. If your resolveRecord() isn’t firing, it’s likely because the Importer is using mass-assignment and only filling fields defined in getColumns(). By default, fields not in the CSV won’t be set unless you take manual action.
Here’s a robust solution:
1. Use the fillRecord Method for Additional Attributes
Most Laravel/Filament importers call a method like fillRecord to fill in additional attributes before saving. It’s better suited for setting programmatic fields than resolveRecord, which replaces the record instance entirely.
Here's how you can do it:
class ContractImporter extends Importer
{
protected static ?string $model = Contract::class;
public static function getColumns(): array
{
return [
ImportColumn::make('contract_description')
->requiredMapping()
->rules(['required']),
ImportColumn::make('contract_type')
->numeric()
->rules(['integer']),
ImportColumn::make('contract_file_path'),
ImportColumn::make('date_executed')
->rules(['date']),
ImportColumn::make('date_start')
->rules(['date']),
ImportColumn::make('date_scheduled_end')
->rules(['date']),
ImportColumn::make('date_end_notify')
->rules(['date']),
ImportColumn::make('date_terminated')
->rules(['date']),
ImportColumn::make('auto_renews')
->requiredMapping()
->boolean()
->rules(['required', 'boolean']),
];
}
public static function fillRecord(
Model $record,
array $row
): Model {
// fill columns from CSV
$record->fill($row);
// add generated fields
$record->contract_number = Contract::getID();
$record->added_by = auth()->id();
$record->commit_status = 'Draft';
return $record;
}
}
2. Remove contract_number from Your Columns
Make sure contract_number is not listed in getColumns, so the importer doesn’t look for that column in the CSV.
3. Make Sure Your Importer Supports fillRecord
Some Filament versions and custom importers use mutateRecordData or similar hooks. If your parent Importer uses a different method name, adapt accordingly (e.g., override mutateRecordData or beforeSave).
Troubleshooting resolveRecord: Your code with resolveRecord creates a new Contract, but if the parent Importer never calls resolveRecord, that’s why your Ray() call isn’t reached. Many importers instantiate the model directly and only use resolveRecord in specific customization flows.
Summary:
- Do NOT list the generated ID in getColumns()
- Use fillRecord to set non-CSV, programmatic fields
- Make sure to call fill($row) to populate other fields
If Your Importer Only Supports mutateRecordData:
public static function mutateRecordData(array $data): array
{
$data['contract_number'] = Contract::getID();
$data['added_by'] = auth()->id();
$data['commit_status'] = 'Draft';
return $data;
}
Pick the hook that matches your Importer base class.
Let me know if you need an example for a specific importer type or class!