simonhamp / laravel-nova-csv-import

The best CSV import component for Laravel Nova
https://novapackages.com/packages/simonhamp/laravel-nova-csv-import
MIT License
168 stars 76 forks source link

404 Error after upload #44

Open alexWaterfront opened 2 years ago

alexWaterfront commented 2 years ago

After i click on choose file and i select a csv document first screen

it just shows me a 404 error see image attached:

image

HeadStudios commented 2 years ago

I just had this issue... so going to check this - first time I'm trying to figure out how this whole thing works... I guess I have to update the files downloaded by my composer require thingie with this new commit let me check

jigsawsoul commented 2 years ago

Same issue for me, it's just returning a 404

HeadStudios commented 2 years ago

Just wanted to pipe in - the link included here: https://github.com/simonhamp/laravel-nova-csv-import/pull/45 - fixed the 404 issue for me. I just copy/pasted the raw file and replaced the src/Http/Controllers/ImportController.php file from here: https://github.com/simonhamp/laravel-nova-csv-import/pull/45/commits/8dd479689e6f96601fbeae4af993aecce06a1faf .... so if you do that it should fix it... however that didn't solve "ALL" my problems because after I did that I could import - everything looks good on the import and it says 28 records imported successfully or whatever... but... nothing is imported!

Hopefully the creator peeks in here - because this has a lot of potential for me and I'm sure the fix to my thing is fairly straightforward - btw for anyone experiencing this issue - let me know if doing what I recommended fixed your issue and if you encounter the "second" import issue I encountered (where everything works... but it doesn't really work if that makes sense)

alexWaterfront commented 2 years ago

Thanks for the input everyone hopefully by getting traction the author will have a look soon. I tried your solution @HeadStudios but unfortunately it didn't work for me I still get 404 error.

HeadStudios commented 2 years ago

@alexWaterfront that's a shame... yes please keep me updated... I am one step ahead (404 page fixed.. imports not working) - but hoping to get resolution.. let's work together and keep each other informed - I'll be checking back here.

gcjbr commented 2 years ago

My PR only prevents the 404, but the Resource causing it can't be configured when imported.

The error goes all the way to NovaRequest's rulesForCreation method, but I can't pinpoint what's the difference between the Resources that are being imported successfully and those which are not

HeadStudios commented 2 years ago

Hm good point, I've only tried one Resource for import - I could technically try other Resources to see if the issue is with my resources.. like I could try and import some Users as that is like the default mode. I appreciate your PR though because copy/pasting that did help me get to the next step.. I don't know why this Debugbar or whatever it is won't show me the SQL query that is attempted to be performed on insert.. I'm new to Laravel and not the best at debugging - but you've given me the idea to test with other resources to try to pinpoint the problem down - and thank for rulesForCreation method to look at. Chrs.

archambaultalex commented 2 years ago

Got the same problem. I am getting a 404 error when uploading the csv file. For me, the error was caused by resources that had a belongsTo field. In ImportController@extractValidationRule the function $resource::rulesForCreation is called which in turn calls the function getCreationRules at /nova/src/PerformsValidation@rulesForCreation on each field. For a reason that I do not understand, if it's called on a belongsTo field, it returns a 404 error.

gcjbr commented 2 years ago

Got the same problem. I am getting a 404 error when uploading the csv file. For me, the error was caused by resources that had a belongsTo field. In ImportController@extractValidationRule the function $resource::rulesForCreation is called which in turn calls the function getCreationRules at /nova/src/PerformsValidation@rulesForCreation on each field. For a reason that I do not understand, if it's called on a belongsTo field, it returns a 404 error.

Same

HeadStudios commented 2 years ago

Hmmmm.... interesting... because the resource I'm importing into - there's a chance that has a BelongsTo field to... or more so a BelongsTo function or something.. I will test without them and see what happens... but I know the table doesn't have any remote fields... what's interseting is that there's no error being made... and I am sooo bad at troubleshooting - like all this stuff you guys are saying - I have no idea how to check that out. On my end I just get a success message - actually I should post what happens on my side here soon.. I feel like I'm so close to a solution though (I even have a success page saying "38 contacts of 38 contacts have been imported" and stuff.

gcjbr commented 2 years ago

If you used my solution, though, it will import, but the fields on the Resource with the relationship won't show in the dropdown to map the fields for import. That's because I simply short circuited the mapping function when it throws any error.

On Sun, 24 Jul 2022 at 23:57, HeadStudios @.***> wrote:

Hmmmm.... interesting... because the resource I'm importing into - there's a chance that has a BelongsTo field to... or more so a BelongsTo function or something.. I will test without them and see what happens... but I know the table doesn't have any remote fields... what's interseting is that there's no error being made... and I am sooo bad at troubleshooting - like all this stuff you guys are saying - I have no idea how to check that out. On my end I just get a success message - actually I should post what happens on my side here soon.. I feel like I'm so close to a solution though (I even have a success page saying "38 contacts of 38 contacts have been imported" and stuff.

— Reply to this email directly, view it on GitHub https://github.com/simonhamp/laravel-nova-csv-import/issues/44#issuecomment-1193499864, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB6DCUWLGK5KEL33I4C5IZLVVX7BDANCNFSM525NRA2A . You are receiving this because you commented.Message ID: @.***>

HeadStudios commented 2 years ago

Yes I'll try and import to users or something with no relationships... the thing is the Resource I'm importing doesn't have any related id fields... like for example Contacts doesn't have any foreign id keys or anything fancy at the database level - https://share.getcloudapp.com/wbuXqE7e - ... so I'm just doing name, mobile, email. The thing is on the Model level I do have the following:

ublic function campaign_contacts() { return $this->belongsToMany(CampaignContact::class); }

So it does belongsTo... but it doesn't have to.. I don't know if I'm making sense - I'm wondering if your mapping short circuits if on the model it has belongsTo... because I can create contacts without associating them (in fact I can't associate them on the creation in nova level) to campaign contacts or anything.. not sure if I described it correctly.. I can try removing that belongs to or campaign_contacts() function too and see if it works - but thanks for clarifying that it short circuits - just trying to figure out this mystery - any input much appreciated!

petervandijck commented 2 years ago

Having the same issue, anyone working on this (aside from the above comments)?

HeadStudios commented 2 years ago

I might put this over to Fiverr and see if someone is willing to work and fix it... if I find a solution I'll come back here and share - you guys better throw me some pennies if I do though lol.

morcov commented 2 years ago

Problem in NovaRequest in method resource by call in BelongsTo::associatableQueryCallable

public function resource()
    {
        return tap(once(function () {
            return Nova::resourceForKey($this->route('resource'));
        }), function ($resource) {
            abort_if(is_null($resource), 404);
        });
    }

Request can't get value $this->route('resource') because there is none. For resolve can use custom request with replacement this method. Example

    public function resource()
    {
          return $this->importResource;
    }

I can't create a pull request right now, maybe later

HeadStudios commented 2 years ago

Problem in NovaRequest in method resource by call in BelongsTo::associatableQueryCallable

public function resource()
    {
        return tap(once(function () {
            return Nova::resourceForKey($this->route('resource'));
        }), function ($resource) {
            abort_if(is_null($resource), 404);
        });
    }

Request can't get value $this->route('resource') because there is none. For resolve can use custom request with replacement this method. Example

    public function resource()
    {
          return $this->importResource;
    }

I can't create a pull request right now, maybe later

Wait.. so I just... find and replace that code and (theoretically) it should work? I will try tomorrow!

pedami commented 2 years ago

Hola tengo el mismo problema. Esperamos que mañana lo resuelva @HeadStudios

Gracias.

HeadStudios commented 2 years ago

Hola tengo el mismo problema. Esperamos que mañana lo resuelva @HeadStudios

Gracias.

Hello Spanish person. Had to translate what you said but yes excited about getting this fixed too.

HeadStudios commented 2 years ago

Problem in NovaRequest in method resource by call in BelongsTo::associatableQueryCallable

public function resource()
    {
        return tap(once(function () {
            return Nova::resourceForKey($this->route('resource'));
        }), function ($resource) {
            abort_if(is_null($resource), 404);
        });
    }

Request can't get value $this->route('resource') because there is none. For resolve can use custom request with replacement this method. Example

    public function resource()
    {
          return $this->importResource;
    }

I can't create a pull request right now, maybe later

This crashed for me when I replaced this function in Nova... or am I meant to make another function? I'm trying to comment the abort part out to see if this puts the CSV import through.. I have no idea what I'm doing lol.

HeadStudios commented 2 years ago

Problem in NovaRequest in method resource by call in BelongsTo::associatableQueryCallable

public function resource()
    {
        return tap(once(function () {
            return Nova::resourceForKey($this->route('resource'));
        }), function ($resource) {
            abort_if(is_null($resource), 404);
        });
    }

Request can't get value $this->route('resource') because there is none. For resolve can use custom request with replacement this method. Example

    public function resource()
    {
          return $this->importResource;
    }

I can't create a pull request right now, maybe later

This didn't help unfortunately :( any other input much appreciated - or if I'm doing something wrong. Chrs!

morcov commented 2 years ago

My PR https://github.com/simonhamp/laravel-nova-csv-import/pull/47

HeadStudios commented 2 years ago

My PR #47

Niiice! Just had a look - can't wait to try over on my side. Looking forward to it!

pedami commented 2 years ago

My PR #47

Niiice! Just had a look - can't wait to try over on my side. Looking forward to it!

Muchas gracias, esto funciona ;-)

HeadStudios commented 2 years ago

My PR #47

Sorry :( - just tried and it has not fixed my issue - I do import and just like before it says success records imported but when I go to look nothing has been imported :(

pedami commented 2 years ago

Hello, it worked for me the second time, because I wasn't passing all the mandatory fields, try to pass all the fields that are mandatory and it will work for you.

HeadStudios commented 2 years ago

Hello, it worked for me the second time, because I wasn't passing all the mandatory fields, try to pass all the fields that are mandatory and it will work for you.

Hey, I have a contacts with only 3 fields (name, email, phone) - I pass all fields and it says success but no records imported :(

HeadStudios commented 2 years ago

It says Imported but... not really - https://share.getcloudapp.com/kpuW9qp1 - btw that #47 pull request did help! But... there's just no import happening despite it saying that is so.. yeh.

heshamwatany commented 2 years ago

solved it for me php artisan vendor:publish --tag=csv-import

HeadStudios commented 2 years ago

solved it for me php artisan vendor:publish --tag=csv-import

Thank you! I am going to try... don't leave!

alexrafuse commented 1 year ago

Hey folks any update here? I tried https://github.com/simonhamp/laravel-nova-csv-import/pull/47 and like @HeadStudios it says its imported but nothing is showing up in the db or logs. Would love to get this working instead of having to write my own custom thing.

HeadStudios commented 1 year ago

Hey bro, I ended up getting this working.. I had to edit the vendor files or fork the repository and make some changes - don't even remember what I did but @alexrafuse if you want to meet me over at the Laravel Discord I'd be happy to share as much as I know as much as time would allow. Chrs!

Erkenz commented 1 year ago

@HeadStudios i have the same issue where i can import but nothing is imported how did you fix it?

rafaelsmith commented 1 year ago

Has anyone made it work?

Erkenz commented 1 year ago

@rafaelsmith no I just made my own standalone import I got the 404 fixed but it just didn't import anything

rafaelsmith commented 1 year ago

@Erkenz So bottom line it's not working? :(

Erkenz commented 1 year ago

@rafaelsmith no not for me but i could help you with the import you can contact me in discord if you want erkenzjordi#5675

simonhamp commented 1 year ago

Hey folks. Please if you can, share the relevant CSV import code, a sample of the CSV data you're trying to import and any relevant DB migrations and I will be more than happy to investigate and fix.

It will be great if you could also let me know what version(s) of Nova and this plugin you've got installed.

HeadStudios commented 1 year ago

Has anyone made it work?

Yeh I had to hack core but I got it working to what I need - I basically did a conditional and I even modified drop downs and everything - I'm on Discord if you want to jump in - I'm in the Laravel group and can share what I did. But it seems like hte guy who made is around now so perhaps he can assist.

rafaelsmith commented 1 year ago

Hey folks. Please if you can, share the relevant CSV import code, a sample of the CSV data you're trying to import and any relevant DB migrations and I will be more than happy to investigate and fix.

It will be great if you could also let me know what version(s) of Nova and this plugin you've got installed.

The file very simple you can see here: https://gist.github.com/rafaelsmith/ed22e90be4c74e7945d8be3390aece63 The Nova version is v4.21.0

Thanks in advance! :)

Stefan-Dressler commented 1 year ago

Hi @simonhamp. 

Firstly, thanks for providing this package. Very usefully. I have tested it yesterday and ran into the issue described here. I tried all versions and 0.4.0 is the last working version for Nova 4. We are also running on Nova 4.21.0.

Maybe this is helpful for you.

torrancemiller commented 1 year ago

It would be really great if this package worked! Has anyone made a working fork of this?

HeadStudios commented 1 year ago

It would be really great if this package worked! Has anyone made a working fork of this?

I did get this working after modifying some stuff though I don't remember exactly what I did lol, I don't think I made a fork either. But I can confirm with some slight changes it does work.

chrillep commented 1 year ago

filter out supported fields from $fieldsCollection before getting fields?

        $fieldsCollection = $fieldsCollection->filter(fn (Field $field) => !($field instanceof BelongsTo));

excludeAttributesFromImport should do this?

rafaelsmith commented 1 year ago

Hey folks. Please if you can, share the relevant CSV import code, a sample of the CSV data you're trying to import and any relevant DB migrations and I will be more than happy to investigate and fix.

It will be great if you could also let me know what version(s) of Nova and this plugin you've got installed.

Hey mate any update for us? :)

simonhamp commented 1 year ago

@rafaelsmith your file isn't a CSV... it's using semicolons. That's why it won't work... I've not configured it to support all of the weird and wonderful ways CSVs might be written...

Can you change your data so that it does use commas?

rafaelsmith commented 1 year ago

@rafaelsmith your file isn't a CSV... it's using semicolons. That's why it won't work... I've not configured it to support all of the weird and wonderful ways CSVs might be written...

Can you change your data so that it does use commas?

Thank you for your reply, unfortunately also after changing it to commas I get the same 404 error. Also the url after upload the file is nova/csv-import/configure/1828f0efd066b0f17ef30c9d446355ea.txt

simonhamp commented 1 year ago

@rafaelsmith why is the extension now .txt? Please make sure it's a .csv file with CSV data inside. The code that handles the files won't know how to treat it otherwise

rafaelsmith commented 1 year ago

@rafaelsmith why is the extension now .txt? Please make sure it's a .csv file with CSV data inside. The code that handles the files won't know how to treat it otherwise

I export CSV file directly from Google Sheets.

hamza-darvis commented 1 year ago

Not working for nova/csv-import/configure/f8b142ec31a75df933caeed75c2f0495.csv Sample csv from https://sample-videos.com/download-sample-csv.php#google_vignette

simonhamp commented 1 year ago

@hamza-darvis which file did you pick to test (how many rows)? And which version of CSV import are you running?