anaseqal / nova-import Goto Github PK
View Code? Open in Web Editor NEWLaravel Nova Import Action
Laravel Nova Import Action
Please give me a clear step by step guide on how to you created an import button.
Thank you
Hi,
in your DispatchAction class line 58
protected static function queueForModels(ActionRequest $request, Action $action, $method, Collection $models)
you typehint $models with Collection, but you use
use Illuminate\Support\Collection;
instead of
use Illuminate\Database\Eloquent\Collection;
this cause this issue:
Argument 4 passed to Anaseqal\NovaImport\Actions\CallQueuedAction::__construct() must be an instance of Illuminate\Database\Eloquent\Collection, instance of Illuminate\Support\Collection given, called in ...
thank you for your great job
Hi,
Plugin seems to be working great, but my app is in French, and Button sticks with the text : "Import Users". At side, the create user buttons says: "Créer Utilisateur", because I named my resource "Utilisateur".
Is there a way to change this ???
I'm using Nova 2.x with Laravel 6
I try to specify a different value in the method name, but the import button is not displayed.
Example
File ImportUsers.php:
class ImportUsers extends Action
{
...
...
public function name() {
return __('ImportTestUsers');
}
...
...
}
File en.json:
{
"ImportTestUsers": "Custom Button Name",
}
If that's the way it's meant to be, then it's a very bad idea.
Thanks for a great package!
I am using this package to import data from JSON-files instead of Excel, which works great. From my point of view, the dependency to maatwebsite/excel
isn't really necessary. It can be required in the project when needed. maatwebsite/excel
requires phpoffice/phpspreadsheet
which in turn requires the PHP zip extension, which in my case is totally unnecessary.
Could the dependency be dropped?
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.
create new action:
php artisan nova:action ImportUsers
enable stand alone option by adding:
public $standalone = true;
composer require maatwebsite/excel
php artisan make:import UsersImport --model=User
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'),
];
}
public function actions(Request $request)
{
return [new Actions\ImportUsers];
}
Happy coding!
It seems that since the action doesn't applies on models. It didn't has record in action_event when the action is triggered.
I tried to add Laravel\Nova\Nova::actionEvent()->forResourceUpdate($user, $model)->save();
it's not working.
Hi @anaseqal,
Is this package only work with the User
resource? I have tried with a newly created resource on Nova v3.3.2 but doesn't appear Import button near.
Hi, Awesome package by the way,
I was wondering if there was a way to pass the Resource type and ID to the action so I can avoid having the ID and type within the CSV itself and just deduct it from where the Request is coming from (which resource page)
Running a diff on the two files, it seems to just be an older version of the Action.php already inside nova. I'll make a PR to remove it.
Hi!
After upgrading to Nova 2.5.0 the import button text disappeared https://prnt.sc/pjwny0 https://prnt.sc/pjwo4d
Hi,
How about reload the page after the import in order to see the resources imported.
It seems to me very odd not seeing any results after the import.
Sharing a solution here for all those who attempt to use this package to import CSV or XLS(X) data into a JSON database field:
Use Case:
Import cell values (e.g. address details) from CSV or XLS files into destination JSON columns.
Solution:
Wrap the array mapping between the database JSON child node and the CSV / XLS column within the following function:
response()->json([ Add array here ])->getData()
Place address code example:
public function model(array $row)
{
return new Client([
'name' => $row['client'],
'location' => response()->json([
'address' => $row['address'],
'street'=> $row['street'],
'house_no'=> $row['house_no'],
'postcode'=> $row['postcode'],
'city'=> $row['city'],
'county'=> $row['county'],
'country'=> $row['country']
])->getData(),
]);
@anaseqal
Would be great to have this somewhere in the readme / documentation as this might be useful for others too.
I have a problem with uploading files, keep getting this error can you help?
call to undefined method App\Nova\Actions\importUsers::show onIndex[]
When enabled on resource SoftDeletes is lost
latest version on nova is used
Hi,
I'm trying to import a CSV, button is displaying well, but when I import I get:
Undefined index 1
Here is my csv file:
papa, [email protected], pipi, 2, 2, 2
mama, [email protected], popo, 1, 1, 1
And here is the associated code:
public function model(array $row)
{
$profiles = Profile::where('id', '>=', 2)->get()->pluck('name', 'id');
$companyId = auth()->user()->company_id;
$operations = Operation::where('company_id', $companyId)->get()->pluck('name', 'id');
return new User([
'name' => $row[0],
'email' => $row[1],
'password' => Hash::make($row[2]),
'profile_id' => $profiles[$row[3]],
'company_id' => $companyId,
'operation_id' => $operations[$row[4]],
]);
}
If I change delimiter coma to semicomas, I get:
Undefined offset 1
What should I do about it ???
I'm using Nova 2.x with Laravel 6
Hi all, I came across this issue following the installation instructions in this package.
I found that one important dependency was missing in the "use statements" which is causing the issue:
While searching for a solution I found this YouTube Video which helped me to track down the root cause.
I am sharing the solution to all who have the same problem getting started with this really amazing package.
Error:
Call to undefined method App\Nova\Actions\ImportResource}::shownOnIndex()
Impact:
Cause:
The use statement "use Laravel\Nova\Actions\Action;" is missing in the example import action "\Nova\Actions\Import{Resource}.php"
Solution:
Add "use Laravel\Nova\Actions\Action;" to the use statements:
Remark:
Please add the use of "use Laravel\Nova\Actions\Action;" to your documentation.
I have added this and made a commit request to get this added. Thanks for the package!
I have followed the setup docs but I can't seem to get the Import button showing on the index page, when I set public $onlyOnIndex = false; I see the action only on the detail page.
When trying to use the package I'm getting:
Trait 'Laravel\\Nova\\Metable' not found at /var/www/vendor/anaseqal/nova-import/src/Actions/Action.php:19
And Trait 'Laravel\\Nova\\AuthorizedToSee' not found at /var/www/vendor/anaseqal/nova-import/src/Actions/Action.php:20
Did you forget to include this traits, or am I missing something?
Nova: 2.9.4
Laravel: 5.8.*
Nova-import: 0.0.2
Am I missing something here?
Problem: Action not appearing on HasMany
relationship.
I have an 'import keys' action on my key resource. Works fine.
The keys have a label group. On the label resource, I have a HasMany
that displays attached keys correctly, but doesn't give me the action to import keys to said label.
There's nothing in the Action
class that would lead me to believe I'm missing a function.
Good day, thank you so much for the work, it's nice to have action button which not refers to specific item of resource!
Do you plan to add action name customization? When I'm trying apply custom name with
public $name
within Action class, then button will just disappear, and thus in javascript need to be implemented some dirty things. The same goes for the title.
Excuse me for bad English :)
This is too big a headline for mobile!
Currently experiencing this weird behavior as described by @vincenzoraco
I had the same problem, I was using this package https://novapackages.com/packages/anaseqal/nova-import which helps me to import resources. The error occurs when you don't have any resource saved on the database.
It seems that Nova is checking if there are any saved resourced, is it the right behavior? It does make sense to me, but it stops us to import the initial data, if any.
So for those who are facing this issue, create a dummy record on the table, then import, and then delete the dummy row
Thanks
How can we display validation errors inside Nova?
I got this error when updating to Nova 2.0.9. I already run `` after update but it still shows that error.
vendor.js?id=eaffe66c3a2800ae7df2:1 TypeError: Cannot set property 'fields' of undefined
at app.js?id=af7f60e144c36d0eb627:1
at Function.pr.tap (nova-import:1)
at p.createPanelForField (app.js?id=af7f60e144c36d0eb627:1)
at app.js?id=af7f60e144c36d0eb627:1
at Array.forEach (<anonymous>)
at p.availablePanels (app.js?id=af7f60e144c36d0eb627:1)
at ln.get (vendor.js?id=eaffe66c3a2800ae7df2:1)
at ln.evaluate (vendor.js?id=eaffe66c3a2800ae7df2:1)
at p.availablePanels (vendor.js?id=eaffe66c3a2800ae7df2:1)
at p.render (app.js?id=af7f60e144c36d0eb627:1)
I use a responsive theme.
When checking on my phone, create button turns into a small (+) button, but Import button doesn't, so it doesn't fit the screen.
It is possible to consider the responsiveness of the button in CSS ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.