Registering an asset:
When you are ready to place the links to the registered assets on your view, you may use the styles or scripts methods:
Dumping assets into a view:
<head> <?php echo Asset::styles(); ?> <?php echo Asset::scripts(); ?> </head>
Sometimes you may need to specify that an asset has dependencies. This means that the asset requires other assets to be declared in your view before it can be declared. Managing asset dependencies couldn't be easier in Laravel. Remember the "names" you gave to your assets? You can pass them as the third parameter to the add method to declare dependencies:
Registering a bundle that has dependencies:
Asset::add('jquery-ui', 'js/jquery-ui.js', 'jquery');
In this example, we are registering the jquery-ui asset, as well as specifying that it is dependent on the jquery asset. Now, when you place the asset links on your views, the jQuery asset will always be declared before the jQuery UI asset. Need to declare more than one dependency? No problem:
Registering an asset that has multiple dependencies:
Asset::add('jquery-ui', 'js/jquery-ui.js', array('first', 'second'));
Retrieving an instance of an asset container:
Dumping that assets from a given container:
Before learning how to conveniently add and dump bundle assets, you may wish to read the documentation on creating and publishing bundle assets.
When registering assets, the paths are typically relative to the public directory. However, this is inconvenient when dealing with bundle assets, since they live in the public/bundles directory. But, remember, Laravel is here to make your life easier. So, it is simple to specify the bundle which the Asset container is managing.
Specifying the bundle the asset container is managing:
Now, when you add an asset, you can use paths relative to the bundle's public directory. Laravel will automatically generate the correct full paths.