Including CSS in Lavavel 5 or 4.3

TL; DR: What is the correct way to reference a stylesheet in Laravel 5?

Background: I use the dev version of Laravel 4.3 (5) because I want to use Socialite, and from the very beginning it makes sense to develop with this. I had a problem getting templates from 4.2

I moved the blade layout files to a new directory structure (resources / templates) and put my CSS in the public / css / folder.

When I load my route / test / all I get is "oops, something seems to have gone wrong."

For testing purposes, I removed the entire syntax of the blade layout from my layouts - the raw HTML code works, but there is no style (since there is no related stylesheet). This suggests that routes, views, and controllers work.

Problem:

In my layouts, if I remove the following, the layouts work:

{{ HTML::style('css/bootstrap.min.css') }} {{ HTML::style('css/style.css') }} 

Question:

What is the correct layout and syntax for including Blade Stylesheet in Laravel 5 and what should I use instead?

+3
laravel laravel-5 blade
source share
3 answers

HtmlBuilder been removed from the Laravel core, so HTML::style() no longer available.

If you want to use it in laravel 5, add the following to your composer.json file with the require key:

 "laravelcollective/html": "~5.0" 

Also note: since HTML::style() returns HTML code, you do not want it to be escaped. Use raw brackets:

 {!! HTML::style('css/style.css') !!} 
+8
source share

By adding an answer to @joseph, for users who prefer not to switch to the new syntax, you can use

 Blade::setRawTags('{{', '}}'); 

and continue the old syntax. it can be installed almost anywhere, but the best choice would be a service provider, say, an inherited service — for 14. you can find further discussion of this subject in laracasts where you can find thoughts about Taylor on that.

0
source share

If you want to use plain HTML, then use this as:

  <link rel="stylesheet" href="/css/folder/style.css"> 
0
source share

All Articles