administrcms/asset-manager

1,075
Install
composer require administrcms/asset-manager
Latest Version:1.1.4
PHP:>=5.5.9
Laravel:5 – 8
License:MIT
Last Updated:Apr 12, 2021
Links: GitHub  ·  Packagist
Maintainer: mirovit

Assets manager

Build Status Code Climate Test Coverage

Installation

Using Composer:

composer require administrcms/asset-manager

Add the service provider:

\Administr\Assets\AssetsServiceProvider::class,

The Facade:

'Asset'    => \Administr\Assets\AssetsFacade::class,

Usage

Base usage

The asset manager works with the Laravel framework. It provides a Facade for easier usage.

You can specify your asset groups by either the add method or using the magical method.

Asset::add('test.css', 'css');
// is the same as
Asset::addCss('test.css');

You can retrieve a group either by the get method or the magical equivelent.

Asset::get('css');
// is the same as
Asset::getCss();

You can also specify a priority for your asset. For example when using the jQuery library, you need to include it before any other library that depends on it.

// The sort is from highest to lowest priority. The default priority is 0.
Asset::addJs('jquery.js', 100);
Asset::add('jquery.js', 'js', 100);

Shortcuts

You can define a shortcut, which is a class that defines multiple assets at once. If you are using a js library that needs to include js and css code, you can make it easier.

// Create a class that implements the Shortcut contract
class WysiwygShortcut implements Administr\Assets\Contracts\Shortcut {
    public function execute()
    {
        Asset::addJs('tinymce.js');
        Asset::addCss('tinymce.css');
        Asset::addCss('tinymce.theme.css');
    }
}

// Register it with the Asset Manager
Asset::shortcut('wysiwyg', WysiwygShortcut::class);

// And then call it like a method of the Manager
Asset::wysiwyg();

It is up to you to decide where to register the shortcuts. A good place would be in a ServiceProvider in you Laravel app.

Related Packages

doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

644,549,754 9,698
laravel/framework

The Laravel Framework.

598,760,099 34,966
laravel/tinker

Powerful REPL for the Laravel framework.

507,193,856 7,441
laravel/serializable-closure

Laravel Serializable Closure provides an easy and secure way to serialize closur...

423,477,751 607
nunomaduro/collision

Cli error handling for console/command-line PHP applications.

403,217,078 4,664

Version History

Version Released PHP Laravel License
1.1.4 >=5.5.9 >=5.2 MIT
1.1.3 >=5.5.9 >=5.2 MIT
1.1.2 >=5.5.9 >=5.2 MIT
1.1.1 >=5.5.9 5.2.* MIT
1.1.0 >=5.5.9 5.2.* MIT