| Package Data | |
|---|---|
| Maintainer Username: | tooleks |
| Maintainer Contact: | tooleks@gmail.com (Oleksandr Tolochko) |
| Package Create Date: | 2016-07-08 |
| Package Last Update: | 2017-06-01 |
| Home Page: | https://packagist.org/packages/tooleks/laravel-asset-version |
| Language: | PHP |
| License: | MIT |
| Last Refreshed: | 2025-11-03 15:15:57 |
| Package Statistics | |
|---|---|
| Total Downloads: | 45,457 |
| Monthly Downloads: | 57 |
| Daily Downloads: | 0 |
| Total Stars: | 7 |
| Total Watchers: | 1 |
| Total Forks: | 3 |
| Total Open Issues: | 0 |
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
PHP >= 7.0, Laravel >= 5.0.
Execute the following command to get the latest version of the package:
composer require tooleks/laravel-asset-version
To register the service simply add Tooleks\LaravelAssetVersion\Providers\AssetServiceProvider::class into your config/app.php to the end of the providers array:
'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:
'aliases' => [
...
'Asset' => Tooleks\LaravelAssetVersion\Facades\Asset::class,
],
Run following command in the terminal to publish the package file resources:
php artisan vendor:publish --provider="Tooleks\LaravelAssetVersion\Providers\AssetServiceProvider" --tag="config"
Configure assets version number in the config/assets.php:
...
'version' => '0.0.1',
...
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:
...
'secure' => null,
...
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:
...
'secure' => null,
...
<link href="{{ Asset::get('path/to/asset.css') }}" rel="stylesheet" type="text/css">
<link href="<?= Asset::get('path/to/asset.css') ?>" rel="stylesheet" type="text/css">