Prebuilt Import Action from Excel | TypeError: Cannot read properties of null

I use to Import the Member List using Prebuilt Import Action. I don't see mistake. Can anyone help me to find the error that I forget to implements? Here is my error:
No description
10 Replies
johnnie_littleshoes
do you have something like
$member->phone
$member->phone
in your code? if $member is null, then you can't retrieve its phone
Abdur Razzaque
Abdur RazzaqueOP4mo ago
No, I don't have something like this. I follow this filament instruction to import data from CSV file. https://filamentphp.com/docs/3.x/actions/prebuilt-actions/import#using-import-options
toeknee
toeknee4mo ago
Does your CSV contain phone? you have set it as required.
Abdur Razzaque
Abdur RazzaqueOP4mo ago
Yes, I check it multiple times.
No description
toeknee
toeknee4mo ago
Can you provide the importer code
Abdur Razzaque
Abdur RazzaqueOP4mo ago
Ofcourse, here it is...
public static function getColumns(): array
{
return [
ImportColumn::make('certified_members_name_english')
->label('Name in English')
->rules(['max:255']),
ImportColumn::make('phone')
->requiredMapping()
->rules(['required', 'max:255']),
ImportColumn::make('password')
->requiredMapping()
->rules(['max:100']),
ImportColumn::make('ssc_school_name')
->label('School Name')
->rules(['max:255']),
ImportColumn::make('district_of_school')
->label('District of School')
->rules(['max:255']),
];
}

public function resolveRecord(): ?Member
{
// return Member::firstOrNew([
// // Update existing records, matching them by `$this->data['column_name']`
// 'phone' => $this->data['phone'],
// ]);

return new Member();
}

public static function getCompletedNotificationBody(Import $import): string
{
$body = 'Your member 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;
}
public static function getColumns(): array
{
return [
ImportColumn::make('certified_members_name_english')
->label('Name in English')
->rules(['max:255']),
ImportColumn::make('phone')
->requiredMapping()
->rules(['required', 'max:255']),
ImportColumn::make('password')
->requiredMapping()
->rules(['max:100']),
ImportColumn::make('ssc_school_name')
->label('School Name')
->rules(['max:255']),
ImportColumn::make('district_of_school')
->label('District of School')
->rules(['max:255']),
];
}

public function resolveRecord(): ?Member
{
// return Member::firstOrNew([
// // Update existing records, matching them by `$this->data['column_name']`
// 'phone' => $this->data['phone'],
// ]);

return new Member();
}

public static function getCompletedNotificationBody(Import $import): string
{
$body = 'Your member 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;
}
toeknee
toeknee4mo ago
have you declared the model in the class? Ahhh I suspect it is
return new Member();
return new Member();
phone will be null here I suspect since new Member() will have all empty fillables I suspect
Abdur Razzaque
Abdur RazzaqueOP4mo ago
I don't understand, what are you talking about?
// Member.php Model
class Member extends Authenticatable
{
use HasFactory, Notifiable;
protected $guard = 'member';
protected $fillable = [
'username',
'phone',
'email',
'password',
// have more field
]
}
// Member.php Model
class Member extends Authenticatable
{
use HasFactory, Notifiable;
protected $guard = 'member';
protected $fillable = [
'username',
'phone',
'email',
'password',
// have more field
]
}
toeknee
toeknee4mo ago
Nevermind I was being dumb, but phone is being null somewhre
Abdur Razzaque
Abdur RazzaqueOP4mo ago
Not only phone. After uploading the CSV file, all data shows null. Only header can be read. I'm not understanding, how can I dump the data from uploaded CSV file. Because the error coming from file uploaded. If the header of csv file can be read, why the data is empty? I know that, somewhere I do mistake. That's why the phone showing null. I have to find the error and I don't know how to do this.
Want results from more Discord servers?
Add your server