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

Nova v3.10.0+ Import "standalone" action #26

Open
anaseqal opened this issue Dec 7, 2020 · 12 comments
Open

Nova v3.10.0+ Import "standalone" action #26

anaseqal opened this issue Dec 7, 2020 · 12 comments
Labels

Comments

@anaseqal
Copy link
Owner

anaseqal commented Dec 7, 2020

Hello,

Nova v3.10.0 introduce a new standalone action for running actions without selecting resources. which make a good use case to import data to your resource without using this package.

Result:

Screenshot

Step by step:

  1. create new action:
    php artisan nova:action ImportUsers

  2. enable stand alone option by adding:

    public $standalone = true;
  1. create an import class for your resource using Laravel Excel.
    composer require maatwebsite/excel
    php artisan make:import UsersImport --model=User
    then in action file:
   public function handle(ActionFields $fields)
    {
        \Maatwebsite\Excel\Facades\Excel::import(new \App\Imports\UsersImport, $fields->file);
        return Action::message('It worked!');
    }

    public function fields()
    {
        return [
            \Laravel\Nova\Fields\File::make('File')
                ->rules('required'),
        ];
    }
  1. register the action into your resource.
public function actions(Request $request)
{
    return [new Actions\ImportUsers];
}

Happy coding!

@anaseqal anaseqal pinned this issue Dec 7, 2020
@phoenixg
Copy link

phoenixg commented Dec 9, 2020

Good to see this feature!

@MCKLtech
Copy link

MCKLtech commented Feb 9, 2021

I'm getting the following error when running the action after following this tutorial:

Call to undefined method App\Nova\Actions\ImportUsers::validateFields()

It seems like Nova Action's have this method but Anaseqal\NovaImport\Actions\Action does not. My ImportUsers extends NovaImport, not Nova.

(Nova v3.21.0)

Solved

It would appear you should extend the Nova Action, not NovaImport.

Can the docs be updated to reflect this?

@urbandario
Copy link

Hello i getting this error, even if i think i setup all things correctly...
Call to undefined method App\Nova\Actions\ImportProducts::shownOnIndex()

@urbandario
Copy link

I'm getting the following error when running the action after following this tutorial:

Call to undefined method App\Nova\Actions\ImportUsers::validateFields()

It seems like Nova Action's have this method but Anaseqal\NovaImport\Actions\Action does not. My ImportUsers extends NovaImport, not Nova.

(Nova v3.21.0)

Solved

It would appear you should extend the Nova Action, not NovaImport.

Can the docs be updated to reflect this?

When i change on from NovaImport to Nova i get
Class "Anaseqal\Nova\Actions\Action" not found

@LaravelLover069
Copy link

LaravelLover069 commented Apr 2, 2022

Hi there, I am getting the same error after applying all the mentioned setup steps:

Call to undefined method App\Nova\Actions\ImportSupervisors::shownOnIndex()

The import process itself is working however I cannot view the resource detail view (data not being displayed).
The index view lists the records, however the error keeps showing up over and over. Please advise how to fix this.

Excel-Import-Error

@LaravelLover069
Copy link

Hi all, I found the solution to this issue

Hello i getting this error, even if i think i setup all things correctly... Call to undefined method App\Nova\Actions\ImportProducts::shownOnIndex()

@Urbanizacija69
I faced the same issue and found the solution for this issue.
I have created an issue record and provided the solution for this.
#33
Cheers

@StevenBokesa
Copy link

StevenBokesa commented May 16, 2022

I am doing the following steps
composer require anaseqal/nova-import
I registered the tool in my NovaServiceProvider.php app/Providers/NovaServiceProvider.php
I created a nova action file and added my importer to the handle() method
I registered my action in my resource then had an error saying
Class Anaseqal\NovaImport\NovaImport contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (Laravel\Nova\Tool::menu)
Any ideas on how to fix this please

@CarlosHidalgo89
Copy link

no support laravel nova 4, @anaseqal is correct?

@CarlosHidalgo89
Copy link

I registered the tool in my NovaServiceProvider.php app/Providers/NovaServiceProvider.php

is laravel nova 4 ?

@Wilquey
Copy link

Wilquey commented Nov 23, 2022

i have the same problem
did you get any solution?

Class Anaseqal\NovaImport\NovaImport contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (Laravel\Nova\Tool::menu)

@CarlosHidalgo89
Copy link

CarlosHidalgo89 commented Nov 23, 2022 via email

@Wilquey
Copy link

Wilquey commented Nov 23, 2022

Thank you CarlosHidalgo89 for the instructions, the replacements were carried out.
However, another error appeared that I could not identify.

Declaration of App\Nova\Actions\ImportUsers::fields() should be compatible with Anaseqal\NovaImport\Actions\Action::fields(Laravel\Nova\Http\Requests\NovaRequest $request)

did you get any solution?

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

No branches or pull requests

8 participants