How do you manage assets in the new Laravel 4? It looks like Taylor Otwell has replaced Asset::add
with something new.
What I am trying to do is have Laravel add my CSS and JS files. There were several ways to do this in Laravel 3, but they seem to be gone now. One was Asset::add
and the other was HTML
. What are the replacements for these?
{{url}} allows you to create a link to a URL on your site -- another benefit is the fact that you can set the second parameter to an array with query string parameters within. {{asset} simply allows you to link to an asset within your public directory -- for example css/main.
The assets folder in the resources directory is for files that need compilation, like views or LESS files. Compiled assets, or plain assets like CSS and JS files should be in public/assets/ .
the asset() method is used to include CSS/JavaScript/images files, you can use it in this cases. Copy Code <link href="{{ asset('css/min.css') }}" rel="stylesheet"> <script src="{{ asset('use.typekit.net/zjb5wvv.js') }}"></script> <img alt="logo" src="{{ asset('images/logo.png') }}">
In Laravel 4 you can use the HTML
class, it's default included in the Laravel Framework package:
Stylesheet:
{{ HTML::style('css/style.css') }}
Javascript:
{{ HTML::script('js/default.js') }}
I use the helper:
<script src="{{ asset('js/jquery-1.9.1.js') }}"></script>
<script src="{{ asset('js/bootstrap.min.js') }}"></script>
See also
vendor/laravel/framework/src/Illuminate/Support/helpers.php
Many other helpers too, e.g. app_path(), various array tools, link_to_route(), link_to_action(), storage_path(), etc.
Laravel 4 doesn't have out of the box asset management. But some packages have been created to handle this kind of thing.
codesleeve/asset-pipeline (my favorite so far)
jasonlewis/basset (had some errors with this)
teepluss/asset (closest to Laravel 3 Asset::add() but doesn't do concatenation or minification)
way/guard-laravel (requires ruby guard gem to run)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With