https://github.com/tooleks/laravel-asset-version
The Laravel Assets Versioning Package
https://github.com/tooleks/laravel-asset-version
assets cache css js laravel laravel-asset php versioning
Last synced: over 1 year ago
JSON representation
The Laravel Assets Versioning Package
- Host: GitHub
- URL: https://github.com/tooleks/laravel-asset-version
- Owner: tooleks
- License: mit
- Created: 2016-07-08T11:09:25.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2017-06-01T16:25:59.000Z (about 9 years ago)
- Last Synced: 2025-04-12T03:17:57.632Z (over 1 year ago)
- Topics: assets, cache, css, js, laravel, laravel-asset, php, versioning
- Language: PHP
- Homepage: https://packagist.org/packages/tooleks/laravel-asset-version
- Size: 18.6 KB
- Stars: 7
- Watchers: 1
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# The Laravel 5 Assets Versioning Package
This package performs versioning of the asset URL resources.
Asset link before versioning:
```
https://website.domain/path/to/asset.css
```
Asset link after versioning:
```
https://website.domain/path/to/asset.css?v=0.0.1
```
## Requirements
PHP >= 7.0, Laravel >= 5.0.
## Installation
### Package Installation
Execute the following command to get the latest version of the package:
```shell
composer require tooleks/laravel-asset-version
```
### App Configuration
#### Service Registration
To register the service simply add `Tooleks\LaravelAssetVersion\Providers\AssetServiceProvider::class` into your `config/app.php` to the end of the `providers` array:
```php
'providers' => [
...
Tooleks\LaravelAssetVersion\Providers\AssetServiceProvider::class,
],
```
If you prefer to use the service via facade interface add `'Asset' => Tooleks\LaravelAssetVersion\Facades\Asset::class` into your `config/app.php` to the end of the `aliases` array:
```php
'aliases' => [
...
'Asset' => Tooleks\LaravelAssetVersion\Facades\Asset::class,
],
```
#### Publishing File Resources
Run following command in the terminal to publish the package file resources:
```shell
php artisan vendor:publish --provider="Tooleks\LaravelAssetVersion\Providers\AssetServiceProvider" --tag="config"
```
#### Configure Assets Version
Configure assets version number in the `config/assets.php`:
```php
...
'version' => '0.0.1',
...
```
## Basic Usage Examples
#### Via Service Object
```php
use Tooleks\LaravelAssetVersion\Contracts\AssetServiceContract;
$assetUrl = app(AssetServiceContract::class)->get('path/to/asset.css'); // 'http://website.domain/path/to/asset.css?v=0.0.1'
$secureAssetUrl = app(AssetServiceContract::class)->get('path/to/asset.css', true); // 'https://website.domain/path/to/asset.css?v=0.0.1'
```
Note: Secure option will be detected automatically if no second argument will be passed into the function and `secure` option configured to `null` in the `config/assets.php`:
```php
...
'secure' => null,
...
```
#### Via Service Facade Class
```php
use Tooleks\LaravelAssetVersion\Facades\Asset;
$assetUrl = Asset::get('path/to/asset.css'); // 'http://website.domain/path/to/asset.css?v=0.0.1'
$secureAssetUrl = Asset::get('path/to/asset.css', true); // 'https://website.domain/path/to/asset.css?v=0.0.1'
```
Note: Secure option will be detected automatically if no second argument will be passed into the function and `secure` option configured to `null` in the `config/assets.php`:
```php
...
'secure' => null,
...
```
#### In The Layout (Blade Template)
```html
```
#### In The Layout (PHP Template)
```html
```