6

I am new to Laravel and am trying to get the css in the public directory to load. The page loads no problem but the CSS gives me a 404 error in firebug:

"NetworkError: 404 Not Found - http://127.0.0.1:8000/css/main.css"

I wrote this in the blade template:

<link href="{{ asset('/css/main.css') }}" rel="stylesheet">

Which outputs:

<link href="http://127.0.0.1:8000/css/main.css" rel="stylesheet">

Which seems correct.

The site is run with php artisan serve. Any suggestions? Thanks!

10
  • Try {{ asset('css/main.css') }} Commented Apr 20, 2015 at 5:21
  • Just tried, still gives me a 404, it outputs the same thing: <link href="http://127.0.0.1:8000/css/main.css" rel="stylesheet"> Commented Apr 20, 2015 at 5:24
  • this should work <link href="/asset/css/main.css" rel="stylesheet"> Commented Apr 20, 2015 at 6:01
  • "NetworkError: 404 Not Found - http://localhost:8000/asset/css/main.css" Commented Apr 20, 2015 at 6:03
  • Does it work when you paste same thing to browser? Commented Apr 20, 2015 at 6:19

3 Answers 3

9

Try:

<link href="{{asset('css/main.css')}}" rel="stylesheet">

OR

<link href="{{url('css/main.css')}}" rel="stylesheet">

OR

If you are using php artisan serve its possible that your public folder is not being used, so use PHP native server instead and specify the public folder as the web root.

Stop artisan serve and try using PHP native server by issuing this command at the root of your Laravel project: php -S localhost:8000 -t public

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

10 Comments

Tried it now, still the same 404
Please where is CSS file located in your public folder?
The default location: ./public/css/main.css
Correct. Running it with php artisan serve
Okay. Please stop artisan serve and try using PHP native server by issuing this command at the root of your Laravel project: php -S localhost:8000 -t public
|
0

If you install Illuminate/HTML you can do

{!!HTML::style('css/styles.css')!!} //styles.css inside public/css folder

or try

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

Comments

0

When you specify a path for your css and JS files, the root of the files need to be in 'project-name\public\' and not 'project-name\'

If you want for example to include with blade 'mytheme.css' which is inside 'mypersonalcss' folder ('mypersonnalcss\mytheme.css') fist add it to the project in 'project-name\public\mypersonnalcss\mytheme.css'

Then add it in your blade file :

<link href="{{ asset('mypersonnalcss\mytheme.css') }}" rel="stylesheet" type="text/css" >

Please see : Laravel 5 not finding css files to learn more about how to add assets to blade files.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.