It looks like your issue is because you’ve added the ->numeric() method, which tells Filament to cast the "contract_type" column to a number before your castStateUsing closure runs. That’s why $state is always 0—it gets converted before you get it. Just remove ->numeric(), and your closure will receive the actual string from the CSV.
Here’s the corrected code:
ImportColumn::make('contract_type')
->castStateUsing(function (?string $state) {
Log::debug('Contract Type from CSV: ' . $state);
if (blank($state)) {
return null;
}
$type = ContractType::where('contract_type_name', 'like', '%' . $state . '%')
->first();
if (empty($type)) {
return null;
}
return $type->id;
})
->requiredMapping()
->rules(['required', 'integer']);
Drop ->numeric(), and you should be golden!