5

This is kind of a stupid question, and I've looked around for similar answers and found some, however they are a bit more specific than what I am asking.

Say I want to include a custom styles.css or scripts.js file, would I just create a css/js folder in resources/views folder, and then call to them in my blade.php files like I would normally do in an HTML file when not using Laravel?

Example: <link type="text/css" rel="stylesheet" href="css/styles.css">

Or is there a different approach to this in Laravel?

1
  • The way I said works, but they do have some more complicated asset managers to deal with things, depending on the complexity of your application, so you may want to look into those first. Commented Jul 30, 2015 at 14:30

2 Answers 2

22

Put your css files into the public folder like public/css/styles.css

Use the asset() function to add css, javascript or images into your blade template.

For Style Sheets

<link href="{{ asset('css/styles.css') }}" rel="stylesheet" type="text/css" >

or

<link href="{{ URL::asset('css/styles.css') }}" rel="stylesheet" type="text/css" >

For Javascript

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

or

 <script type="text/javascript" src="{{ URL::asset('js/scripts.js') }}"></script>

You may also be interested to have a look at Laravel's Elixir to process your styles and javascript.

Sign up to request clarification or add additional context in comments.

2 Comments

What's the difference between asset and URL::asset?
one is shorter than the other ;) The asset() function is a helper and shorter than using the laravel facade URL::asset(). The result is the same. It's a personal preference thing I guess.
1

put your style.css file in inside css folder named: /css AND your js file inside js folder named: /jsput below code in your html file.

Your css files

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

And js files

<script type="text/javascript" src="{{ URL::asset('js/jquery.min.js') }}"></script>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.