FilamentF
Filament11mo ago
Tieme

Import validation

Hi all,

I have a simple importer, only the sheet that i want to import hase some columns with NULL as string

How can i cast or save it as null in database?

Both options below wont work and throws me a validation error that The from email field is required.

I want the value to be null if string of state == 'NULL'

Imports\ImportColumn::make('from_email')
      ->ignoreBlankState()
      ->castStateUsing(function (?string $state): ?string {
        if (blank($state) or (\Str::upper($state) == 'NULL')) {
            return null;
        }
    
        return $state;
      })

Imports\ImportColumn::make('from_email')
      ->ignoreBlankState()
      ->fillRecordUsing(function ($record, string $state): void {
          if(\Str::upper($state) == 'NULL'){
            $record->from_email = null;
          }
          $record->from_email = $state;
      })


My migration has the field als nullable

$table->text('from_email')->nullable();


Also i dont see where the validation would be happening because there is no validation on the fields.

Thanks for the help!
Solution
I think it was a cache issue, after removing all the cache and tried it again. No errors.
Was this page helpful?