LaravelDaily/Laravel-Vue-First-CRUD

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

Opened this issue · 9 comments

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

After that, i've used this command:

  • Copy .env.example file to .env and edit database credentials there
  • Run composer install
  • Run php artisan key:generate
  • Run php artisan migrate
  • Run npm install
  • Run npm run dev

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,

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

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!!

@hiren004 your APP_URL should not contain /public/

@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

@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

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

Thank you!

@hiren004 1. put the files in the main folder change your URL to just http://my_ip_address
2. or change the Vue code to be more flexible and take your URL prefix, we won't do that for you sorry

Hello, Thanks.

Let me try to make it fixed!

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

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