laravel / nova-issues

554 stars 35 forks source link

Export as CSV throwing Too few arguments exception #4647

Closed lintoncaldecott closed 2 years ago

lintoncaldecott commented 2 years ago

Description:

I am trying to export a resource to csv, or a collection of resources to CSV using Laravel\Nova\Actions\ExportAsCsv;

use Laravel\Nova\Actions\ExportAsCsv;

 public function actions(NovaRequest $request)
    {
        return [
            ExportAsCsv::make()->nameable(),
        ];
    }

According to the docs at https://nova.laravel.com/docs/4.0/resources/#csv-export But I get the following in my laravel.log after running the action. [2022-07-29 06:38:54] local.ERROR: Too few arguments to function Laravel\Nova\Actions\ExportAsCsv::fields(), 0 passed in /Users/linton/Desktop/dev/pulse/vendor/epartment/nova-dependency-container/src/Http/Requests/ActionRequest.php on line 21 and exactly 1 expected {"userId":11,"exception":"[object] (ArgumentCountError(code: 0): Too few arguments to function Laravel\Nova\Actions\ExportAsCsv::fields(), 0 passed in /Users/linton/Desktop/dev/pulse/vendor/epartment/nova-dependency-container/src/Http/Requests/ActionRequest.php on line 21 and exactly 1 expected at /Users/linton/Desktop/dev/pulse/vendor/laravel/nova/src/Actions/ExportAsCsv.php:78) [stacktrace]

This is also true if I specify withFormat like this

    public function actions(NovaRequest $request)
    {
        return [
            ExportAsCsv::make()->nameable()->withFormat(function ($model) {
                return [
                    'ID' => $model->getKey(),
                    'Name' => $model->name,
                ];
            }),
            ];
    }
crynobone commented 2 years ago

This appear to caused by /vendor/epartment/nova-dependency-container/src/Http/Requests/ActionRequest.php and we have no control over 3rd party packages.