simonhamp / laravel-nova-csv-import

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

Instance Exception when referenced Resource extends Laravel\Nova\Resource and not App\Nova\Resource #8

Closed stiknoltz closed 5 years ago

stiknoltz commented 5 years ago

First off thanks for creating this library. I've found it very useful.

I did notice the following which can occur in certain instances where you're including other Nova Resource generating Packages.

There is a type hint on line 48 of src/Http/Controllers/ImportController.php for an App\Nova\Resource class which fails if the Resource is from another vendor package which generally reference Laravel\Nova\Resource and not one created locally.

Since Laravel\Nova\Resource as NovaResource is already imported, the fix was was just a matter of changing the Resource type hint to NovaResource

I think #7 might be related to this issue.

stiknoltz commented 5 years ago

Wasn't sure of the best way to provide this, but here's a diff of the proposed solution:


index 2bad80b..1d19f00 100644
--- a/src/Http/Controllers/ImportController.php
+++ b/src/Http/Controllers/ImportController.php
@@ -45,7 +45,7 @@ class ImportController
             $model = $resource::$model;

             return new $resource(new $model);
-        })->mapWithKeys(function (Resource $resource) use ($request) {
+        })->mapWithKeys(function (NovaResource $resource) use ($request) {
             return [$resource->uriKey() => $resource->creationFields($request)];
         });```
simonhamp commented 5 years ago

@stiknoltz I've just released this fix. Could you update your version and let me know if it's working for you?