Asset Component is a port of Laravel 3 Asset for Orchestra Platform.

Overview

Asset Component for Orchestra Platform

Asset Component is a port of Laravel 3 Asset for Orchestra Platform. The component main functionality is to allow asset declaration to be handle dynamically and asset dependencies can be resolve directly from the container. It however is not intended to becoma an asset pipeline package for Laravel, for such purpose we would recommend to use Grunt or Gulp.

tests Latest Stable Version Total Downloads Latest Unstable Version License Coverage Status

Table of Content

Version Compatibility

Laravel Asset
5.5.x 3.5.x
5.6.x 3.6.x
5.7.x 3.7.x
5.8.x 3.8.x
6.x 4.x
7.x 5.x
8.x 6.x

Installation

To install through composer, run the following command from terminal:

composer require "orchestra/asset"

Configuration

Add following service providers in config/app.php.

'providers' => [

    // ...

    Orchestra\Asset\AssetServiceProvider::class,
    Collective\Html\HtmlServiceProvider::class,
    
],

Aliases

You might want to add Orchestra\Support\Facades\Asset to class aliases in config/app.php:

'aliases' => [

    // ...

    'Asset' => Orchestra\Support\Facades\Asset::class,

],

Usage

Registering Assets

The Asset class provides a simple way to manage the CSS and JavaScript used by your application. To register an asset just call the add method on the Asset class:

Registering an asset:

Asset::add('jquery', 'js/jquery.js');

The add method accepts three parameters. The first is the name of the asset, the second is the path to the asset relative to the public directory, and the third is a list of asset dependencies (more on that later). Notice that we did not tell the method if we were registering JavaScript or CSS. The add method will use the file extension to determine the type of file we are registering.

Dumping Assets

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>
    {!! Asset::styles() !!}
    {!! Asset::scripts() !!}
head>

Above code can also be simplified as:

<head>
    {!! Asset::show() !!}
head>

Asset Dependencies

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', ['first', 'second']);

Asset Containers

To increase response time, it is common to place JavaScript at the bottom of HTML documents. But, what if you also need to place some assets in the head of your document? No problem. The asset class provides a simple way to manage asset containers. Simply call the container method on the Asset class and mention the container name. Once you have a container instance, you are free to add any assets you wish to the container using the same syntax you are used to:

Retrieving an instance of an asset container:

Asset::container('footer')->add('example', 'js/example.js');

Dumping that assets from a given container:

{!! Asset::container('footer')->scripts() !!}

Asset Versioning

Another option to increase response time is by utilizing browser caching, while there few ways to do this we pick last modified time as our way to version the Asset.

Asset::container()->addVersioning();

// or alternatively
Asset::addVersioning();

Note: this would only work with local asset.

You can remove adding versioning number by using:

Asset::container()->removeVersioning();

// or alternatively
Asset::removeVersioning();
Comments
  • Blade @jsIn not working

    Blade @jsIn not working

    I'm not sure if it's a bug, but:

    @jsIn('footer', $dinamicUrl) is not working but Asset::container('footer')->add('url', $dinamicUrl); is working fine.

    opened by pepoteloko 2
  • Missing dependencies (orchestral/support) when installing through composer

    Missing dependencies (orchestral/support) when installing through composer

    There seems to be a missing dependency when installing orchestral/asset through composer.

    If you adjust the composer.json like mentioned in the installation documentation it will install orchestral/asset without any errors but as soon as you add the Alias to config/app, the Facade couldn't be resolved. The package orchestral/support seems to be missing in the dependency tree.

    Workaround: adding orchestral/support manually to composer.json. Then everything can be resolved fine again.

    opened by disperun 2
  • Asset dependency

    Asset dependency

    Hi,

    I tried to use asset dependency like this, but it seems not working:

    Asset::add('one', 'assets/js/one.js');
    
    Asset::container('footer')
    ->add('two', 'assets/js/two.js', 'one');
    
    // view
    {{ Asset::container('footer')->scripts() }}
    

    one.js isn't shown in the page, it shows only two.js. Did I miss something here?

    PS. I'm on Laravel 4.2 and using orchestral/asset 2.2

    Thanks!

    question 
    opened by kutukode 2
  • Add illuminate/filesystem as a requirement

    Add illuminate/filesystem as a requirement

    illuminate/filesystem is defacto requirement of this package, so it should be listed as such.

    The package directly depends on it in the Dispatcher. If a user of this package also uses Laravel, it will be installed anyway. If the user doesn't use Laravel, then it would need to be manually installed. In any case, the package has to be installed in order for orchestral/asset to work.

    opened by sergejostir 1
  • Integrate HtmlBuilder

    Integrate HtmlBuilder

    Currently the whole laravie/html is pulled in. It is mostly non-relevant to this package except for the HtmlBuilder. I suppose it makes more sense to integrate parts of HtmlBuilder that are actually required for this package instead of depending on mostly non-relevant dependency.

    opened by sergejostir 1
  • Check, if start of the extension matches in Asset::add

    Check, if start of the extension matches in Asset::add

    Currently Asset::add method checks, if the whole extension matches 'css' and if not assumes that it belongs to scripts container.

    This change makes sure that only the start of the extension matches 'css', so if we for example use 'something.css?id=12345', it will properly recognize it as style and not put it in scripts container.

    This is useful, if you want to use your custom versioning (for example using Laravel Mix).

    opened by sergejostir 1
  • Argument 2 passed to Orchestra\Asset\Asset::script() must be of the type string, null given

    Argument 2 passed to Orchestra\Asset\Asset::script() must be of the type string, null given

    Hi, I've tried using @css and @js with urls that just start with //, however, it generates the error above:

    Argument 2 passed to Orchestra\Asset\Asset::script() must be of the type string, null given

    I've hand a quick look at the code, and it seems that you are testing for http, https and // URLs but the error is thrown before it gets to isLocalPath()

    I dont understand enough how these blade tags are being called to figure out where the problem might be - hoping you could provide some pointers.

    So, using @css('https://cdn/url') works, but using @css('//cdn/url') throws the above error.

    (I'm using v3.8.0.)

    opened by leenooks 1
  • Can`t install version 3.4 - Composer minimum-stability

    Can`t install version 3.4 - Composer minimum-stability

    Is not version 3.4 stable?

    Composer error: Your requirements could not be resolved to an installable set of packages. Problem 1 - Installation request for orchestra/asset ~3.4 -> satisfiable by orchestra/asset[v3.4.0]. - orchestra/asset v3.4.0 requires orchestra/contracts ~3.4.0 -> satisfiable by orchestra/contracts[3.4.x-dev] but these conflict with your requirements or minimum-stability.

    opened by andersondalmina 1
Releases(v6.1.0)
Owner
Orchestra Platform
Orchestra Platform provide all the boilerplate for your application, so you can create awesomeness.
Orchestra Platform
Magewire is a Laravel Livewire port for Magento 2.

Magewire is a Laravel Livewire port for Magento 2. The goal is to make it fun and easy to build modern, reactive and dynamic interfaces, without leaving the comfort of Magento's core layout and template systems. Magewire can be the missing piece when you intend to build dynamic and reactive features, but don't require or feel comfortable working with a full JavaScript framework like Vue or React.

Magewirephp 120 Jan 2, 2023
Adds phone number functionality to Laravel based on the PHP port of Google's libphonenumber API by giggsey.

Laravel Phone Adds phone number functionality to Laravel based on the PHP port of Google's libphonenumber API by giggsey. Table of Contents Demo Insta

null 2.1k Jan 2, 2023
PHP port of Underscore.js

Underscore.php Underscore.php is a PHP port of Underscore.js. In addition to porting Underscore's functionality, Underscore.php includes matching unit

Brian Haveri 1.2k Dec 25, 2022
Adds phone number functionality to TYPO3 based on the PHP port of Google's libphonenumber API by giggsey

TYPO3 Phone Adds phone number functionality to TYPO3 based on the PHP port of Google's libphonenumber API by giggsey. Installation composer require si

Simon Schaufelberger 3 Oct 25, 2022
laravel - Potion is a pure PHP asset manager for Laravel 5 based off of Assetic.

laravel-potion Potion is a pure PHP asset manager for Laravel based off of Assetic. Description Laravel 5 comes with a great asset manager called Elix

Matthew R. Miller 61 Mar 1, 2022
This is a plugin written in the PHP programming language and running on the PocketMine platform that works stably on the API 3.25.0 platform. It helps to liven up your server with Tags!

General This is a plugin written in the PHP programming language and running on the PocketMine platform that works stably on the API 3.25.0 platform.

Thành Nhân 4 Oct 21, 2021
Theme and asset management for laravel

Laravel-Themevel Themevel is a Laravel theme and asset management package. You can easily integrate this package with any Laravel based project. Featu

Shipu Ahamed 339 Dec 23, 2022
Theme and asset management for laravel

Laravel-Themevel Themevel is a Laravel theme and asset management package. You can easily integrate this package with any Laravel based project. Featu

Shipu Ahamed 339 Dec 23, 2022
A Laravel package to speed up deployment by skipping asset compilation whenever possible.

Airdrop for Laravel Read the full docs at hammerstone.dev/airdrop/docs. Hammerstone Airdrop for Laravel is a package that speeds up your deploys by sk

Hammerstone 160 Nov 24, 2022
Laravel Livewire full page component routing.

Laravel Livewire Routes Laravel Livewire full page component routing. This package allows you to specify routes directly inside your full page Livewir

null 22 Oct 6, 2022
Laravel Livewire form component with declarative Bootstrap 5 fields and buttons.

Laravel Livewire Forms Laravel Livewire form component with declarative Bootstrap 5 fields and buttons. Requirements Bootstrap 5 Installation composer

null 49 Oct 29, 2022
Laravel component to create gorgeous Charts.css charts.

Laravel component to create gorgeous Charts.css charts. This package will help you generate CSS only charts based on the Charts.css library. Installat

Maarten Paauw 105 Sep 26, 2022
Livewire component that brings Spotlight/Alfred-like functionality to your Laravel application.

About LivewireUI Spotlight LivewireUI Spotlight is a Livewire component that provides Spotlight/Alfred-like functionality to your Laravel application.

Livewire UI 792 Jan 3, 2023
A TALL-based Laravel Livewire component to replace the (multiple) select HTML input form with beautiful cards.

TALL multiselect cards A TALL-based Laravel Livewire component to replace the (multiple) select HTML input form with beautiful cards. Table of content

Frederic Habich 19 Dec 14, 2022
Laravel Composable View Composers Package - Compose View Composers from Component Composers

Laravel Virtuoso Laravel Composable View Composers Package Increase flexibility and reduce code duplication by easily composing complex View Composers

Yitzchok Willroth 68 Dec 29, 2021
Customizable Feedback Component for Laravel

Laravel Feedback Component allows you to easily implement a Customer Feedback component on your website. It is build with VueJS but can be implemented in any kind of Laravel Project. You just need to drop a few lines in your layout.

Clément Rigo 254 Dec 25, 2022
Laravel Livewire component to show Events in a good looking monthly calendar

Livewire Calendar This package allows you to build a Livewire monthly calendar grid to show events for each day. Events can be loaded from within the

Andrés Santibáñez 680 Jan 4, 2023
Livewire component that brings Spotlight/Alfred-like functionality to your Laravel application.

About Wire Elements Spotlight Wire Elements Spotlight is a Livewire component that provides Spotlight/Alfred-like functionality to your Laravel applic

Wire Elements 790 Dec 27, 2022
A dynamic table component for Laravel Livewire - For Slack access, visit:

A dynamic Laravel Livewire component for data tables. Bootstrap 4 Demo | Bootstrap 5 Demo | Tailwind Demo | Demo Repository Installation You can insta

Anthony Rappa 1.3k Jan 1, 2023