LaravelDaily / Laravel-Vue-First-CRUD

Simple demo project for Laravel 5.5 and Vue.js with one CRUD operation.
257 stars 156 forks source link

Api call not working, got errors while call any of api #7

Open hiren004 opened 6 years ago

hiren004 commented 6 years ago

Hello, I've cloned your URL to download the demo project.

After that, i've used this command:

Then i've register one user and try to login. Login successful, but when i try to create new company, i got this error:

Error: Request failed with status code 404 at createError (app.js:1031) at settle (app.js:31164) at XMLHttpRequest.handleLoad (app.js:905)

When i see in network tab, there's 404 error when calling an api.

Can you please help me with this??

Thanks,

PovilasKorop commented 6 years ago

@hiren004 check what URLs are you calling, and what should be URLs in routes/api.php file, also check your .env file for APP_URL. Also check what is your /public folder. Probably one of these settings are not correct so API is calling different URL than it should.

hiren004 commented 6 years ago

Hello @PovilasKorop Thanks for you fast reply!

In my APP_URL=http://my_ip_address/hiren-work/Laravel-Vue-First-CRUD/public/

Nothing changed any of code in routes/api.php file or any else also in the whole code.

Don't know why it's not working!

Thank you!!

PovilasKorop commented 6 years ago

@hiren004 your APP_URL should not contain /public/

hiren004 commented 6 years ago

@PovilasKorop I've remove /public/ but still not call any api.

It'll take the path like: http://my_ip_address/api/v1/companies instead of http://my_ip_address/hiren-work/Laravel-Vue-First-CRUD/api/v1/companies

PovilasKorop commented 6 years ago

@hiren004 oh because our app assumes you don't have any subfolders, that your main URL is ip address or domain. The call is done from root folder: axios.post('/api/v1/companies

hiren004 commented 6 years ago

Hello @PovilasKorop Then what is the solution to fix this??

Thank you!

PovilasKorop commented 6 years ago

@hiren004 1. put the files in the main folder change your URL to just http://my_ip_address

  1. or change the Vue code to be more flexible and take your URL prefix, we won't do that for you sorry
hiren004 commented 6 years ago

Hello, Thanks.

Let me try to make it fixed!

Anyway, thank you for co-operate!! Much appreciated! :)

simplysaif commented 5 years ago

For any one who is passing by looking for solution: if we remove the first / in the request url , it will work. For example when creating companies we send post ajax request to URL /api/v1/companies it will cause 404 but if we use api/v1/companies ajax request will be sent to correct URL Still checking with it Will post an update if face any issue