Skip to content
Advertisement

Laravel Export: Attempt to read property “second_key” on null

I need to export data with Laravel Export, but the code return ErrorException: Attempt to read property "second_key" on null.

My code:

JavaScript

I’ve tried to check using this:

print_r(json_encode($data->json_data));

and this is the result:

JavaScript

I’ve also done this:

JavaScript

and the excel cell returns the same result:

JavaScript

Advertisement

Answer

As @dbf said in the comment section, I have to handle empty rows. I have checked several times in the database, and maybe I missed that one blank row. Anyway, this is how I handle those values:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement