定制 tobya/laravel-version 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

tobya/laravel-version

Composer 安装命令:

composer require tobya/laravel-version

包简介

Semantic app versioning for Laravel with git integration.

README 文档

README

Latest Version on Packagist Total Downloads

Laravel Version

Semantic versioning for Laravel applications with git integration.

History

This is based on eznix86/laravel-version at https://github.com/eznix86/laravel-version . However I required some changes that did not align so i have created this version.

Installation

composer require tobya/laravel-version

Publish the configuration and version file:

php artisan vendor:publish --tag=version-config
php artisan vendor:publish --tag=version-json

Usage

Commands

# Show current version
php artisan version:show

# Bump version
php artisan version:bump patch      # 1.0.0 → 1.0.1
php artisan version:bump minor      # 1.0.0 → 1.1.0
php artisan version:bump major      # 1.0.0 → 2.0.0

# Pre-release versions
php artisan version:bump alpha      # 1.0.0 → 1.0.0-alpha.1
php artisan version:bump beta       # 1.0.0 → 1.0.0-beta.1
php artisan version:bump rc         # 1.0.0 → 1.0.0-rc.1

# With build metadata
php artisan version:bump patch --build=123              # 1.0.0 → 1.0.1+123
php artisan version:bump minor --build=$(git rev-parse --short HEAD)

# Skip git commit/tag
php artisan version:bump patch --no-git

# Set version to specific value
php artisan version:set 2.0.0         # Set version to 2.0.0
php artisan version:set 1.2.3-alpha.1  # Set version with pre-release
php artisan version:set 1.0.0+build.1  # Set version with build metadata
php artisan version:set 2.1.0 --no-git  # Skip git integration

# Set version from latest git tag
php artisan version:set --match-git-tags            # Use latest git tag as version (commits, doesn't create tag)
php artisan version:set --match-git-tags --no-git   # Use latest git tag but skip commit/tag

Helper

// Mirrors the Version Facade

version()->get();              // "1.0.0"
version()->major();            // 1
version()->minor();            // 0
version()->patch();            // 0
version()->preRelease();       // null or "alpha.1"
version()->build();            // null or "123"
version()->isStable();         // true
version()->isPreRelease();     // false

// Comparisons
version()->gt('0.9.0');                  // true
version()->isGreaterThan('0.9.0');       // true (alias of gt)
version()->gte('1.0.0');                 // true
version()->isGreaterThanOrEqualTo('1.0.0'); // true (alias of gte)
version()->lt('2.0.0');                  // true
version()->isLessThan('2.0.0');          // true (alias of lt)
version()->lte('1.0.0');                 // true
version()->isLessThanOrEqualTo('1.0.0'); // true (alias of lte)
version()->eq('1.0.0');                  // true
version()->isCompatibleWith('1.0.0');    // true (alias of eq)
version()->neq('2.0.0');                 // true
version()->isNotEqualTo('2.0.0');        // true (alias of neq)

Blade

<footer>@version</footer>  <!-- outputs: v1.0.0 (with default prefix) -->

The @version directive automatically includes the configured prefix.

Facade

use Tobya\Version\Facades\Version;

Version::get();
Version::incrementMinor();

Configuration

// config/version.php
return [

    /*
    |--------------------------------------------------------------------------
    | Version Prefix
    |--------------------------------------------------------------------------
    |
    | This value is prepended to the version string when using the @version
    | Blade directive. Set to an empty string to disable the prefix.
    |
    */

    'prefix' => 'v',

    /*
    |--------------------------------------------------------------------------
    | Git Integration
    |--------------------------------------------------------------------------
    |
    | When enabled, version bumps will automatically create a git commit and
    | tag. You can customize the commit message and tag format using the
    | {version} placeholder which will be replaced with the new version.
    |
    */

    'git' => [
        'enabled' => true,
        'commit_message' => 'Bump version to {version}',
        'tag_format' => 'v{version}',
    ],

];

Artisan About

The package automatically registers the version in Laravel's about command:

php artisan about

This will display your application version in the Application section.

Production Protection

To prevent accidental version changes in production, add this to your AppServiceProvider:

use Tobya\Version\Version;

public function boot(): void
{
    Version::prohibitCommands($this->app->isProduction());
}

Or prohibit commands individually:

use Tobya\Version\Commands\VersionBumpCommand;
use Tobya\Version\Commands\VersionSetCommand;

public function boot(): void
{
    VersionBumpCommand::prohibit($this->app->isProduction());
    VersionSetCommand::prohibit($this->app->isProduction());
}

License

MIT

统计信息

  • 总下载量: 9
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-05-30

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固