Laravel 5.7 - CSS and JS not loading using URL::asset
Solution 1
The asset()
helper prepends the base URL to the path you supply.
The base URL is the location of index.php (in this case: http://localhost/mysite/).
If you don't want index.php inside /public you will need to use public/ inside your asset path, like this:
asset("public/css/style.css")
Same for the js files, I hope you understand.
Solution 2
You have 3 possibilites
- Use a tool like Valet
- Use VirtualHost
- Or the easiest, use the command
php artisan serve
in your project and browse http://localhost:8000 see Local Development Server
Edit : I forgot Homestead
Ankit
Updated on August 27, 2021Comments
-
Ankit over 2 years
I am new in laravel. I setup laravel 5.7 on my local system and put js and css into public folder but when hitting my site url on browser, site is not loading any css and js.
Site structure :
app bootstrap config database public -css -js -images resources -views -includes -layouts -pages routes tests vendor index.php server.php .env
Note : I have cut .htaccess and index.php files and put these on root to run site without public in path.
Here is how I am calling url : CSS :
{{ URL::asset('css/style.css') }}
JS :
{{ URL::asset('js/query-1.11.1.min.js') }}
When seeing source code, the url looks like this :
http://localhost/mysite/css/style.css
So can anybody help me out from this issue ?
Thanks in advance.