Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include CSS in laravel 5 running with artisan?

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!

like image 785
Benjamin Dowson Avatar asked Apr 20 '15 05:04

Benjamin Dowson


1 Answers

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

like image 136
Emeka Mbah Avatar answered Sep 25 '22 02:09

Emeka Mbah