Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Akhmadcoder's avatar

Laravel 6 vue js web api requesting to server root

Hi there, I am developing laravel 6 / vue js app. I got several web api's, working on my local machine perfect, but when I put project to server, web api requesting root instead of correct one. using axios, but tried all other get request types, all fail. when try to get list of users, it is requesting to "http://host_root_ip/api/user" should be "http://host_root_ip/project_name/public/api/user" So please help

0 likes
9 replies
Sinnbeck's avatar

How are you calling these urls?

If you do, /api/userit will always start from the domain

Akhmadcoder's avatar

here is my vue js code:

        loadUsers(){
            axios.get('/api/user')
            .then(({ data }) => (this.users = data.users))
            .catch(function(error){
                swal.fire({
                    icon: 'error',
                    title: 'Oops...',
                    text: 'Qandaydir Xatolik Boldi!',
                    footer: 'Xato: '+response.data.message
                  })
            })
        },
Akhmadcoder's avatar

but tried with full url as well, not worked in any try. Anybody knows what is the problem here?

Sinnbeck's avatar

Well if you can call it on the full route manually in the browser just chance this

axios.get('/projectname/public/api/user')

If not, we will need more information. What url is the base for the website? Why is it in a sub folder? Can you access any routes manually?

Akhmadcoder's avatar

Thank you for you reply and help, I put a code like you said,

loadUsers(){ axios.get('/plastik/public/api/user') .then(({ data }) => (this.users = data.users)) .catch(function(error){ swal.fire({ icon: 'error', title: 'Oops...', text: 'Qandaydir Xatolik Boldi!', footer: 'Xato: '+response.data.message }) }) },

but still fails, here is my website full url: http://45.76.216.68/plastik/public/ We bought this server a week ago, and I newly installed apache, mysql and php. Also laravel 6 has installed passport for security api. Here many api's in that project, and all have the same problem, I put axios default url as well window.axios.defaults.baseURL = 'http://45.76.216.68/plastik/public'; but not worked. I put 2 htaccess files on the server, one is on the root folder and the second one is in public folder on the server.

this api full url has to be http://45.76.216.68/plastik/public/api/user I tried from postman, it is asking login password, because I installed passport for api security. So that is all for now.

munazzil's avatar

check below command in your cmd,

   php artisan route:list

i guess you have to pass user_id as well.

Akhmadcoder's avatar

here is my route list: GET|HEAD | api/user | user.index | App\Http\Controllers\API\UserController@index | api,auth:api |

Akhmadcoder's avatar

my ubuntu server I am using multiple projects on one server

Akhmadcoder's avatar

problem solved, I put the following code to header and problem solved.


<base href="{{ asset('http://ip_address/project1/public/') }}" target="_blank">

Please or to participate in this conversation.