© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•12mo ago•
13 replies
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.
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;
      })
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();
$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.
Jump to solution
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Import Failed Validation
FilamentFFilament / ❓┊help
3y ago
How can show import validation error from failed_import_rows column?
FilamentFFilament / ❓┊help
3y ago
validation
FilamentFFilament / ❓┊help
2y ago
validation
FilamentFFilament / ❓┊help
3y ago