laravel-nova-csv-import icon indicating copy to clipboard operation
laravel-nova-csv-import copied to clipboard

404 Error after upload

Open alexWaterfront opened this issue 2 years ago • 59 comments

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

alexWaterfront avatar Jul 07 '22 13:07 alexWaterfront

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

HeadStudios avatar Jul 20 '22 04:07 HeadStudios

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

jigsawsoul avatar Jul 21 '22 08:07 jigsawsoul

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)

HeadStudios avatar Jul 21 '22 09:07 HeadStudios

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.

alexWaterfront avatar Jul 21 '22 10:07 alexWaterfront

@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.

HeadStudios avatar Jul 21 '22 10:07 HeadStudios

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

gcjbr avatar Jul 23 '22 22:07 gcjbr

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.

HeadStudios avatar Jul 24 '22 04:07 HeadStudios

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.

archambaultalex avatar Jul 25 '22 00:07 archambaultalex

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

gcjbr avatar Jul 25 '22 00:07 gcjbr

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.

HeadStudios avatar Jul 25 '22 02:07 HeadStudios

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: @.***>

gcjbr avatar Jul 25 '22 13:07 gcjbr

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!

HeadStudios avatar Jul 25 '22 13:07 HeadStudios

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

petervandijck avatar Jul 25 '22 19:07 petervandijck

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.

HeadStudios avatar Aug 08 '22 07:08 HeadStudios

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

morcov avatar Aug 12 '22 12:08 morcov

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!

HeadStudios avatar Aug 12 '22 13:08 HeadStudios

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

Gracias.

pedami avatar Aug 13 '22 02:08 pedami

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 avatar Aug 13 '22 07:08 HeadStudios

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 avatar Aug 13 '22 14:08 HeadStudios

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!

HeadStudios avatar Aug 13 '22 14:08 HeadStudios

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

morcov avatar Aug 13 '22 15:08 morcov

My PR #47

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

HeadStudios avatar Aug 13 '22 15:08 HeadStudios

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 ;-)

pedami avatar Aug 13 '22 16:08 pedami

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 :(

HeadStudios avatar Aug 13 '22 20:08 HeadStudios

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.

pedami avatar Aug 13 '22 21:08 pedami

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 avatar Aug 14 '22 06:08 HeadStudios

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.

HeadStudios avatar Aug 18 '22 10:08 HeadStudios

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

heshamwatany avatar Sep 28 '22 22:09 heshamwatany

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

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

HeadStudios avatar Sep 28 '22 23:09 HeadStudios

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.

alexrafuse avatar Nov 08 '22 21:11 alexrafuse