gdn-dev/laragit-version

Simple Laravel package to manage versions using VERSION files or Git tags

1.0.3 2025-09-04 04:07 UTC

This package is auto-updated.

Last update: 2025-09-22 00:20:51 UTC


README

Latest Version on Packagist Tests Total Downloads

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')
  1. First checks for a VERSION file in your project root
  2. If found, uses the content as the version
  3. If not found, checks if Git is available
  4. If Git is available, tries to get the version from Git tags
  5. If Git is not available or no tags found, returns "0.0.0" as default
  6. 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