1

I'm new to MVC and Laravel, and I'm trying to include CSS but getting a 404 error. The URL it's generating is...

http://localhost/testing_laravel/css/app.css

If I use the URL this way instead...

http://localhost/testing_laravel/public/css/app.css

It works fine.

My question is why do the tutorials and documentation not use '/public'? Is there something I am not aware of? Please guide me on how I should use URLs for assets.

{{ asset('css/app.css') }}

bilalq
  • 7,279
  • 3
  • 22
  • 28
Mohsin
  • 179
  • 4
  • 13
  • If you need to put **/public** in the URL for it to work, then it sounds like you haven’t set your document root correctly. How are you serving the Laravel application? Using the built-in PHP server, Artisan serve, MAMP, other? – Martin Bean Nov 28 '18 at 08:33

2 Answers2

1

The asset() helper prepends the base URL (http://localhost/testing_laravel) to the given path 'css/app.css'. Within the Laravel directory structure, these assets live in the /public folder and Laravel knows that.

When you create your virtual host for your Laravel install you need to make the /public directory the root. Or, try php artisan serve.

Karl Hill
  • 12,937
  • 5
  • 58
  • 95
-1

You are missing the port http://localhost:8000/testing_laravel/css/app.css

Just open command line & point to root of your project, Then run php artisan serve.

This is the proper way.

{{ asset('css/app.css') }} will point to the public directory

sadaiMudiNaadhar
  • 354
  • 1
  • 12