Laravel Asset Management
- Article
- Comment (2)
Laravel Asset Management is the custom and necessary things to add your Custom CSSĀ and JS files into the Laravel Working Area. We are going to discuss about the ways to add Assets into it. In laravel 3, you can use the Asset method to add styles and javascripts into it.
Just use the following line of codes.
Asset::add('kv_js', 'js/kv_js.js');
Here it accepts two parameters,
1. Name of the assets, given by our own convinence,
2. files location under public directory.
It will collect the informations with help of file extension, either js or css file. But we need to use dump method to use these assets on live.
<head> <?php echo Asset::styles(); ?> <?php echo Asset::scripts(); ?> </head>
Just simple to add the Custom Assets into it. If you are using Laravel 4, Than you can use the following trick to add your assets into it.
Assets::add('filename.extension');
This is also similar to the existing method. You can add array of Assets into it.
Assets::add(array('kv/kv_js.js', 'kv/kv_css.css'));
Likewise you can add many with it. Not only the localy hosted files, also you can add the CDN host files too.
Assets::add('//cdn.example.com/jquery.js'));
And in your view files, just add the following functions to get the list of Assets which are updated with it.
echo Assets::css(); echo Assets::js();
And another way is also available. You can simply add files separately like the following one.
After Laravel 4, you can use the following method to add Assets into it.
{{ HTML::style('css/kv_css.css') }} {{ HTML::style('js/kv_js.css') }}
That’s it to play with assets .
Laravel 4 doesn’t have Asset class so you can’t use Asset::
Yes, i know, in the end i specified an alternative method. Laravel 4 doesnot support Assets. But earlier versions uses the Asset and all.