Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

laravel

blade

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.

like image 418
Pete Avatar asked Mar 05 '13 19:03

Pete


People also ask

Why CSS is not working in laravel?

Try using Mix to copy the assets from the /vendor dirs to your /public dirs (ie /public/css and /public/js). Then use those paths for your assets in the html. Don't think you should be loading assets from the vendor dir.

Where to put js file in Laravel?

Where is mix js laravel? Consider a typical Laravel install. By default, your JavaScript entry point will be located at ./resources/js/app.


1 Answers

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.
like image 127
gan Avatar answered Oct 06 '22 01:10

gan