simonhamp / laravel-nova-csv-import

The best CSV import component for Laravel Nova
https://novapackages.com/packages/simonhamp/laravel-nova-csv-import
MIT License
166 stars 76 forks source link

Importer.php $this->attributes uninitialized and throw Exception on foreach #34

Closed redsend closed 2 years ago

redsend commented 2 years ago

This is the point where there is the error, I'm trying to debug to understand why it happens. As you can see, the foreach on the attributes fails, because $this->attributes is null

Schermata 2022-01-27 alle 11 17 29

.

dnl4 commented 2 years ago

Same here. Can't figure why.

Laravel 8 Laravel nova 3.30.0 Fresh installation

falconsmilie commented 2 years ago

@simonhamp this is the change that broke it.

I you revert that change the upload will work, but then you get some other issues. I have this weird behaviour where if I don't set public static function canImportResource(Request $request) on a Nova resource, it goes into an infinite loop. Strangley enough the resource you implement that method on is then not listed in the Resource dropdown. I could only replicate this behaviour on User Resource. If I add to another resource, i just get the infinite loop after upload.

It also doesn't seem to support CSV separated by ;.

simonhamp commented 2 years ago

Is anyone willing to submit a PR with a test case?

falconsmilie commented 2 years ago

I've only been working with CSV and needed to set some config values in the maatwebsite/excel config so it would accept ; separator. I can never get this tool to accept XLSX, i don't know why, upload always fails.

Here's what i've found in reference to working with CSV.

As i noted earlier, there is an infinite loop scenario which can occur. It seems to happen when you have resources which extend the same model. For example two models extending Authenticatable.

sergioaraos commented 2 years ago

Any news about this issue?

Laravel 8.83 Laravel nova 3.31.0

simonhamp commented 2 years ago

Folks, simply sharing a screenshot of the code (I know the code 😂) or reporting which versions of the main components that you're running is not much help.

💡 If you would like me to assist in solving this issue, you need to make it easy for me to replicate the problem. For that you should share the following:

  1. A sample of your data file (a couple of rows is enough)
  2. The configuration of your Nova resource (i.e. the fields)
  3. The model class that it interrogates
  4. The migration for that table

If for some reason you are uncomfortable or unable to share that code here, let me know and I'll provide another way for you to share 👍🏼