9

vue app is inside : C:\xampp\htdocs\booking

Laravel api is inside : C:\xampp\htdocs\booking-api

FYI : vue app is working on http://localhost:8080

If the folder structure is like above, then app works fine i can call the api like this,

axios.get('http://localhost/booking-api/public/Rooms').then((response)=>this.items = response.data);

But I want booking-api folder inside booking folder. If I place it and if I call the api like below,

axios.get('/booking-api/public/Rooms').then((response)=>this.items = response.data);

It wont work and the console window is like this,

Request URL:http://localhost:8080/booking-api/public/Rooms
Request Method:GET
Status Code:404 Not Found

So, how can I place api project inside vue app and how to call the api from vue.

12
  • When you placed booking-api inside booking did you re-serve your server or not ? Commented Jul 20, 2017 at 7:39
  • @Maraboc, working on it Commented Jul 20, 2017 at 7:47
  • Can't you just setup two virtual hosts each one with a named domain? Much much easier that way. Commented Jul 20, 2017 at 7:49
  • @Maraboc , after re-serving no luck Commented Jul 20, 2017 at 7:56
  • Try php artisan cache:clear and then re-serve again ! Commented Jul 20, 2017 at 8:09

1 Answer 1

2

Okay i guess you used vue.js webpack build in your project. Steps.

  1. serve your vue.js projet using npm run dev
  2. for npm run dev the default server for vue would be localhost:8080

Now your api-part

  1. It doesn't matter where you put it. Install laravel using follow normal procedures;serve it using php artisan serve. it will run normally on 127.0.0.1 or localhost:8000.

  2. Lets assume: a script on a sample component axios.post('localhost:8000/api/postData',data).then((response) => {//do something here}

While posting here you should take care of the Cross Origin Resource Sharing, or may be csrf issues if you remove the existing component.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.