composer require botble/assetsFor version <= 5.4:
Add to section providers of config/app.php:
// config/app.php
'providers' => [
...
Botble\Assets\Providers\AssetsServiceProvider::class,
];And add to aliases section:
// config/app.php
'aliases' => [
...
'Assets' => Botble\Assets\Facades\AssetsFacade::class,
];All assets resource will be manage in config file so we need to publish config to use.
php artisan vendor:publish --provider="Botble\Assets\Providers\AssetsServiceProvider" --tag=configAdd to your master layout view, in head tag:
{!! \Assets::renderHeader() !!}and before body tag close:
{!! \Assets::renderFooter() !!}\Assets::addScripts(['key-of-assets-in-config-file']);Example:
\Assets::addScripts(['app', 'bootstrap', 'jquery']);\Assets::addStyles(['key-of-assets-in-config-file']);Example:
\Assets::addStyles(['bootstrap', 'font-awesome']);\Assets::removeScripts(['key-of-assets-in-config-file']);Example:
\Assets::removeScripts(['bootstrap']);\Assets::removeStyles(['key-of-assets-in-config-file']);Example:
\Assets::removeStyles(['font-awesome']);- Set version for assets. Add to
.env
ASSETS_VERSION=1.0Then all assets will be added ?v=1.0
- Change to online mode
ASSETS_OFFLINE=falseThen assets will be loaded from CDN if it's defined in config file.
- To disable versioning:
ASSETS_ENABLE_VERSION=falseMIT © Sang Nguyen