gdn-dev / laragit-version
Simple Laravel package to manage versions using VERSION files or Git tags
Fund package maintenance!
gdn-dev
Open Collective
Requires
- php: ^8.1
- laravel/framework: ^9.0|^10.0|^11.0|^12.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- pestphp/pest: ^1.0 || ^2.0
- spatie/ray: ^1.28
README
A simple Laravel package to manage versions in your project using either VERSION files or Git tags. No complex configuration required.
✨ Features
- 🚀 Zero Configuration - Works out of the box
- 📄 VERSION File Support - Read version from VERSION files
- 🎯 Git Integration - Uses your existing Git tags as fallback
- 🤐 Silent Git Errors - No error logs when Git is not available
- 🔧 Blade Directive - Easy template integration
- 📱 Laravel 9-12 - Supports Laravel 9, 10, 11, and 12
📋 Requirements
- PHP 8.1 or higher
- Laravel 9.0 - 12.x
📦 Installation
Install the package via Composer:
composer require gdn-dev/laragit-version
The package will automatically register itself via Laravel's auto-discovery.
🚀 Quick Start
Basic Usage
use GenialDigitalNusantara\LaragitVersion\Facade as LaragitVersion; // Get version with default formatting echo LaragitVersion::show(); // "Version 1.0.0" // Get compact version echo LaragitVersion::show('compact'); // "v1.0.0" // Get version info as array $info = LaragitVersion::getVersionInfo();
Using VERSION File
// Create VERSION file in project root file_put_contents(base_path('VERSION'), '2.1.0'); // Use normally echo LaragitVersion::show(); // "Version 2.1.0" echo LaragitVersion::show('compact'); // "v2.1.0"
Blade Templates
Use the convenient Blade directive:
{{-- Default format --}} @laragitVersion {{-- Compact format --}} @laragitVersion('compact')
Service Container
// Via service container $version = app('gdn-dev.laragit-version')->show(); // Via dependency injection public function __construct(LaragitVersion $laragitVersion) { $this->version = $laragitVersion->show(); }
🎯 How It Works
The package uses a simple approach:
'version' => file_exists(base_path('VERSION')) ? trim(file_get_contents(base_path('VERSION'))) : (isGitAvailable() ? trim(exec('git describe --tags --abbrev=0 2>/dev/null')) : '0.0.0')
- First checks for a VERSION file in your project root
- If found, uses the content as the version
- If not found, checks if Git is available
- If Git is available, tries to get the version from Git tags
- If Git is not available or no tags found, returns "0.0.0" as default
- Never produces error logs when Git is not available
📄 License
The MIT License (MIT). Please see License File for more information.
👥 Credits
⭐ Show Your Support
Give a ⭐️ if this project helped you!
Made with ❤️ by Genial Digital Nusantara