How to work with scripts and style sheets in Laravel 5.1

Asked

Viewed 1,244 times

2

I’m new to Laravel 5.1 (actually any Laravel) and I’m having a hard time understanding how to work with style sheets and simple scripts. On several sites, I see that I need to add an element to my Composer.json which is the "laravelcollective/html": "~5.0" but in others I have found saying that working in this way is already outdated for version 5.1

Someone has a good tutorial (in Portuguese) that gives me this light and does not leave the initial scope of Laravel 5.1?

  • You want to import files, that’s it?

  • need to know how I put a file assets\css\style.css in my master.blade.php, that’s all

2 answers

5


Assuming:

public/css 
public/js

You can do the following:

<link href="{{ asset('css/aqr.css') }}" media="all" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="{{ asset('js/aqr.js') }}"></script>

or:

{{ HTML::script('js/aqr.js'); }}

{{ HTML::style('css/aqr.css'); }}

But to use the second option you need to install Illuminate/HTML, follow the link.

  • but according to the documentation I read, all of mine assets should stay inside the resouces folder... even though I have them there I still have to keep something like a production version in the public folder?

  • https://blog.butecopensource.org/tutorial-laravel-5/ puts just read right, it talks to use in public folder but save something in Resources/Assets

  • 1

    The best way at all times is the second option. But when you lower Laravel 5, the library HTML does not come together. You have to install the part by Composer.

1

Help a little more do so:

<link href="{!! asset('css/aqr.css') !!}" media="all" rel="stylesheet" type="text/css" />

<script type="text/javascript" src="{!! asset('js/aqr.js') !!}"></script>

This way you will be using the new syntax for the Blade in Laravel 5.1, remembering that the old syntax:

{{ }}

It is depreciated and soon will be removed, so always use the new:

{!! !!}
  • very good, thank you, so I won’t have to go through my files Blade so early

Browser other questions tagged

You are not signed in. Login or sign up in order to post.