simonhamp / laravel-nova-csv-import

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

conflict with bolechen/nova-activitylog #20

Closed kulcsarbalazs closed 4 years ago

kulcsarbalazs commented 4 years ago

In the resource of the bolechen/nova-activitylog package has static $model = null. This caused this error:

Class name must be a valid object or a string {"userId":1,"exception":"[object] (Symfony\Component\Debug\Exception\FatalThrowableError(code: 0): Class name must be a valid object or a string at [laravel source path]\vendor\simonhamp\laravel-nova-csv-import\src\Http\Controllers\ImportController.php:54)

This correction works in ImportController.php:44

if(!isset($static_vars['canImportResource']) && !is_null($resource::$model)) {
    return true;
}

return isset($static_vars['canImportResource']) && $static_vars['canImportResource'] && !is_null($resource::$model);
smartens80 commented 4 years ago

I found the issue for us was that 'Nova::resources' included resources from other packages we were using that caused different issues (eg: Bolechen\NovaActivitylog\Resources\Activitylog, Vyuldashev\NovaPermission\Role, Vyuldashev\NovaPermission\Permission).

Quick dirty fix was to simply remove any resources that aren't prefixed with 'App\Nova' in our case

$resources = collect(Nova::$resources);

// only allow '\App\Nova' resources
$filtered = $resources->filter(function ($value, $key) {
    if (substr($value, 0, 8) == 'App\Nova') {
        return true;
    }
});
$resources = collect($filtered->all());
simonhamp commented 4 years ago

This should be fixed by #23 which I’ll release soon.