Search code examples
phplaravellaravel-blade

Laravel stylesheets and javascript don't load for non-base routes


Okay--I know this is a really elementary issue, but I can't figure it out. This is a question regarding Laravel.

Basically, I have my stylesheets embedded in my default layout view. I'm currently just using regular css to link them, such as:

<link rel="stylesheet" href="css/app.css" />

It works great when I am at a single level route such as /about, but stops working when I go deeper, such as /about/me.

If I look at Chrome's developer console I see some of the following errors (only for the deeper routes):

Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://example.dev/about/css/app.css".

So clearly it is now looking for the css inside the "about" folder--which of course isn't a folder at all.

I just want it to look in the same place for the assets regardless of the route.


Solution

  • For Laravel 4 & 5:

    <link rel="stylesheet" href="{{ URL::asset('assets/css/bootstrap.min.css') }}">
    

    URL::asset will link to your project/public/ folder, so chuck your scripts in there.


    Note: For this, you need to use the "Blade templating engine". Blade files use the .blade.php extension.