stack stack - 21 days ago 5
PHP Question

How to attach an external CSS file to the master page correctly?

I have a web master which all other views will be set in it. Noted that I use MVC structure (Laravel framework). And here is my directory:

/myweb
/resources
/views
/master
/app.blade.php -- this is web master
/home.blade.php
/show.blade.php
/public
/css
/app.css


Now I attach
app.css
in the
app.blade.php
file like this:

<link rel="stylesheet" href="css/font-awesome.css">


Well, something odd happens here ^ ..
app.css
will be found when I open
home.blade.php
, but it will be not found when I open
show.blade.php
.

Note: If I attach
app.css
like this:

<link rel="stylesheet" href="../css/font-awesome.css">


then it will work for
show.blade.php
, but it doesn't work for
home.blade.php
.

Why? And how can I fix it? I mean how can I write a path which works for both pages?

Answer

Try using like this:

<link href="{{ URL::to('css/style.css') }}" rel="stylesheet">

Here is reference: https://medium.com/@zwacky/laravels-url-to-vs-url-asset-fd427ed6f7ef#.zcmf83z03