redberryproducts / laravel-version
This is my package laravel-version
Fund package maintenance!
RedberryProducts
Requires
- php: ^8.2
- illuminate/contracts: ^10.0||^11.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- larastan/larastan: ^2.9
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.1.1||^7.10.0
- orchestra/testbench: ^9.0.0||^8.22.0
- pestphp/pest: ^2.34
- pestphp/pest-plugin-arch: ^2.7
- pestphp/pest-plugin-laravel: ^2.3
- phpstan/extension-installer: ^1.3
- phpstan/phpstan-deprecation-rules: ^1.1
- phpstan/phpstan-phpunit: ^1.3
- spatie/laravel-ray: ^1.35
README
This Laravel package generates dynamic version badges that reflect the current application version or Composer version based on various conditions. The badges can be easily displayed in your application and updated automatically based on your environment.
Features
- Display the application version from the
.env
file. - Display the Composer version from
composer.json
. - Generate dynamic SVG badges to show the versions.
- Customizable routes for accessing version and badge data.
Installation
Install the package via Composer:
composer require redberryproducts/laravel-version
Publish Configuration
After installation, publish the configuration file:
php artisan vendor:publish --tag=laravel-version-config
This will create a config/version.php file where you can set your application version:This will create a config/version.php file where you can set your application version:
return [ 'app_version' => env('APP_VERSION', 'N/A'), ];
Usage
Routes
This package provides two routes for fetching version information and generating badges.
- Application Version: Retrieves the current version of your application.
- URL:
/application/version
- Controller:
VersionController@index
- Returns both the environment version (from .env) and the composer version (from composer.json).
- URL:
- Version Badge: Generates an SVG badge with dynamic content based on the requested provider (either composer or env).
- URL:
/application/version/badge?provider={composer|env}&environment={optional}
- Controller:
VersionBadgeController
- URL:
Example Badge
You can include the badge in your application as an SVG by embedding the URL in your frontend or views:
<img src="{{ route('application.version.badge', ['provider' => 'composer']) }}" alt="Composer Version Badge"> <img src="{{ route('application.version.badge', ['provider' => 'env']) }}" alt="Environment Version Badge">
Blade Views
The package also comes with two Blade files for rendering the version and badges.
app.blade.php
: Displays both the environment and composer versions using the badge component.@include('version::badge', ['label' => 'Environment Version', 'version' => $envVersion]) @include('version::badge', ['label' => 'Composer Version', 'version' => $composerVersion])
badge.blade.php
: Generates the SVG for the badge based on the label and version provided.
Configuration
The package uses the following environment variable in your .env
file:
APP_VERSION=1.0.0
By default, if APP_VERSION
is not set, it will display N/A.
Customization
To customize the badge, you can replace 'badge_blade' => 'version::badge',
in the config/version.php
file with your
custom blade file.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request or open an issue.
- Fork the repository.
- Create a feature branch:
git checkout -b feature-branch
. - Commit your changes:
git commit -m 'Add some feature'
. - Push to the branch:
git push origin feature-branch
. - Open a pull request.