Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I got error Declaration of App\Nova\Actions\ImportProducts::fields... must be compatible with ... #38

Open
sergeynilov opened this issue Nov 22, 2024 · 0 comments

Comments

@sergeynilov
Copy link

In Laravel 10 / nova 4.27 app I added "anaseqal/nova-import": "^0.0.6"
and I defined app/Nova/Actions/ImportProducts.php actions :

<?php

namespace App\Nova\Actions;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Collection;
//use Laravel\Nova\Actions\Action;
use Anaseqal\NovaImport\Actions\Action; // I DECLARE THESE 2 FILES
use Anaseqal\NovaImport\NovaImport;

use Laravel\Nova\Fields\ActionFields;
use Laravel\Nova\Fields\File;
use Laravel\Nova\Http\Requests\NovaRequest;
use Maatwebsite\Excel\Excel;

class ImportProducts extends Action
{
    use InteractsWithQueue, Queueable;

    public function name()
    {
        return __('Import products from xls file');
    }

    public function handle(ActionFields $fields, Collection $models)
    {
        Excel::import(new \App\Imports\ImportProducts, $fields->file);
    }

    public function fields(NovaRequest $request)
    {
        return [
            File::make('File')
            ->rules('required'),
        ];
    }
}

I got error :


[2024-11-22 13:54:10] local.ERROR: Declaration of App\Nova\Actions\ImportProducts::fields(Laravel\Nova\Http\Requests\NovaRequest $request) must be compatible with Anaseqal\NovaImport\Actions\Action::fields() {"userId":1,"exception":"[object] (Symfony\\Component\\ErrorHandler\\Error\\FatalError(code: 0): Declaration of App\\Nova\\Actions\\ImportProducts::fields(Laravel\\Nova\\Http\\Requests\\NovaRequest $request) must be compatible with Anaseqal\\NovaImport\\Actions\\Action::fields() at /mnt/_work_sdb8/wwwroot/lar/NovaProducts/app/Nova/Actions/ImportProducts.php:46)
[stacktrace]
#0 /mnt/_work_sdb8/wwwroot/lar/NovaProducts/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(244): Symfony\\Component\\ErrorHandler\\Error\\FatalError->__construct(message: '...', code: '...', error: '...', traceOffset: '...', traceArgs: '...', trace: '...')
#1 /mnt/_work_sdb8/wwwroot/lar/NovaProducts/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(231): Illuminate\\Foundation\\Bootstrap\\HandleExceptions->fatalErrorFromPhpError(error: '...', traceOffset: '...')
#2 /mnt/_work_sdb8/wwwroot/lar/NovaProducts/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(255): Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleShutdown()
#3 /mnt/_work_sdb8/wwwroot/lar/NovaProducts/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(0): Illuminate\\Foundation\\Bootstrap\\HandleExceptions->Illuminate\\Foundation\\Bootstrap\\{closure:/mnt/_work_sdb8/wwwroot/lar/NovaProducts/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php:254-256}()
#4 {main}
"}

How it can be fixed ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant