Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 4: What is the replacement for Asset::add?

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?

like image 271
sehummel Avatar asked Jan 07 '13 22:01

sehummel


People also ask

What is the difference between asset and URL in laravel?

{{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.

Where do I put assets in laravel?

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/ .

What is asset function in laravel?

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') }}">


3 Answers

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') }}
like image 194
Ben Bos Avatar answered Oct 19 '22 02:10

Ben Bos


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.

like image 32
Dirk Avatar answered Oct 19 '22 02:10

Dirk


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)

like image 8
Sandy Wilbourn Avatar answered Oct 19 '22 01:10

Sandy Wilbourn