botble / assets
Laravel assets management
Installs: 199 816
Dependents: 2
Suggesters: 0
Security: 0
Stars: 46
Watchers: 4
Forks: 23
Open Issues: 0
Requires
- php: ^7.1.3|^8.0|^8.1|^8.2|^8.3
- laravel/framework: ^5.6|^6|^7|^8|^9|^10|^11.0
Requires (Dev)
- mockery/mockery: ^1.0
- phpunit/phpunit: ^6.1|^7.0|^8.0|^9.0|^10.0|^11.0
README
Installation
composer require botble/assets
For 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=config
Add to your master layout view, in head
tag:
{!! \Assets::renderHeader() !!}
and before body
tag close:
{!! \Assets::renderFooter() !!}
Methods
Add scripts
\Assets::addScripts(['key-of-assets-in-config-file']);
Example:
\Assets::addScripts(['app', 'bootstrap', 'jquery']);
Add styles
\Assets::addStyles(['key-of-assets-in-config-file']);
Example:
\Assets::addStyles(['bootstrap', 'font-awesome']);
Remove scripts
\Assets::removeScripts(['key-of-assets-in-config-file']);
Example:
\Assets::removeScripts(['bootstrap']);
Remove styles
\Assets::removeStyles(['key-of-assets-in-config-file']);
Example:
\Assets::removeStyles(['font-awesome']);
Others
- Set version for assets. Add to
.env
ASSETS_VERSION=1.0
Then all assets will be added ?v=1.0
- Change to online mode
ASSETS_OFFLINE=false
Then assets will be loaded from CDN if it's defined in config file.
- To disable versioning:
ASSETS_ENABLE_VERSION=false
Contributors
License
MIT © Sang Nguyen