Open ThaDaVos opened 4 years ago
So I required the 2.0-dev version of the package with composer require maatwebsite/laravel-nova-excel:^2.0.x-dev
Now, how would one include the import tool so it can be used?
I believe only the following steps are required:
Maatwebsite\LaravelNovaExcel\Tools\ Import
to your toolsBelongsToImport
to your modelImportExcel
action to your resource actionsFinally had the time again to work further on the project, but I think we're missing a step as right after changing my tools()
inside my NovaServiceProvider.php
to the following I'm getting an error as show below:
/**
* Get the tools that should be listed in the Nova sidebar.
*
* @return array
*/
public function tools()
{
return [
\Maatwebsite\LaravelNovaExcel\Tools\Import::class
];
}
My fault, registering it wrong...
@patrickbrouwers is it possible to override which resource/model it uses?
We've got the following relations
List
-> Data
And we want to run the action from the List
resource, which only has a name field, create the needed Data
models and link them to the list -> is this possible? Or should I copy the code in the package and extend on it?
Don't think I have accounted for something like that.
as far as I can see in the code, you're not - still thinking about a way I can make it work -> maybe override the controller or something but I don't know how... -> maybe add some hooks/callbacks, just thinking out loud
I wouldn't mind being able to configure the resource you want to import to on the action. Feel free to PR something like that.
I would first have to use a different of way of getting the source code then, maybe as a submodule, so I can change code - any tips?
I'm getting a beautiful error:
nvm... the issue is with how I setup my docker instance
I've got it partially working already, I can now call the action from my Lists
resource and it fills the Data
resource - still struggling to find a good way to hook into this so one can set attributes on the created models, for example to set the relations etc - also trying to find a way to supply extra information which can be used to create the List
it self at the same time
Any idea's @patrickbrouwers ?
Big question @patrickbrouwers -> How does the ImportExcel action actually run? I don't see a handle
function being specified
It doesn't technically run the action (handle method), I only use the action to determine if it should show the button or not. Then it just goes via a controller call: https://github.com/Maatwebsite/Laravel-Nova-Excel/blob/2.0/src/Http/Controllers/UploadsImportsController.php#L47
I noticed - sorry for not mentioning it - I'm almost done, currently writing the after import hook - how can one get the models it created during the import after line https://github.com/Maatwebsite/Laravel-Nova-Excel/blob/2.0/src/Http/Controllers/UploadsImportsController.php#L47
Or do I need to use a different method on the importer for that? Maybe the toCollection?
Got that working too -> I added a hasMany
relation on the Import model which connects with the resources->model:
/**
* @return HasMany
*/
public function models()
{
$model = Nova::modelInstanceForKey($this->resource);
return $this->hasMany(get_class($model));
}
Got it fully working now! Don't know if it's meant this way, but I can import from one resource, fill another and then link it up together
I'll make a PR later on so you can see what I changed
My changes can be seen here: https://github.com/ThaDaVos/Laravel-Nova-Excel/commit/76a5176faf5eec98c81e5288f22a89d10291557c
@patrickbrouwers here's the promised Pull-Request: https://github.com/Maatwebsite/Laravel-Nova-Excel/pull/88
@patrickbrouwers I made some additional fixes regarding null values in excel sheets
Hey thanks for the PR, I currently don't have a lot of time to look at it. Also releasing 2.0 will most likely also still take a while. Feel free to keep using your own fork, and if you have anymore improvements feel free to add them to the PR! :)
Hi! any news on this?
No sorry
Thank you! I'm new to laravel and laravel nova, and I'm using this package to export my tables. Works really great :)
Do you have a work around or a recommendation to make imports? this really seems a good way to go but as an alternative, do you know any other package that makes import from the data exported from this one?
There are a few packages that have used the Laravel Excel base package like this one: https://packagist.org/packages/anaseqal/nova-import You can have a look at packagist: https://packagist.org/?query=laravel%20nova%20import I haven't tried or used any of them, so I'm not sure which one is good and works.
Prerequisites
Description
There is progress being made for a Nova Import Tool. This issue is opened to serve as a point to ask questions.
PR: https://github.com/Maatwebsite/Laravel-Nova-Excel/pull/70 Twitter: https://twitter.com/patrickbrouwers/status/1143467691577171968