'Project works fine when accessing via 127.0.0.1:8000 but error via localhost public folder

I have a project (test) that works perfectly fine when accessed via 127.0.0.1:8000 but when I access it via localhost/test/public, errors occur.

1. app.js and app.css are not found

my solution:

 <!-- defined before -->
<link href="{{ mix('css/app.css') }}" rel="stylesheet">
<script src="{{ mix('js/app.js') }}" defer></script>

<!-- solution: change`mix` to`asset` -->
<link href="{{ asset('css/app.css') }}" rel="stylesheet">
<script src="{{ asset('js/app.js') }}" defer></script>

I'm not sure if this is the correct solution but the error is gone for now. BUT there is a new error.

2. API can't be found even though the API is being shown in php artisan route:list

I have worked on a Laravel project before with just vanillaJS and jQuery and it works fine in both 127.0.0.1:8000 and localhost/test/public but this project I'm working on now is Laravel with Vuejs 3 so maybe I'm missing some setup?



Solution 1:[1]

All public APIs on Laravel are http(s)://domain.name/api/yourroute

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1