PHPackages                             ekoukltd/version - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. ekoukltd/version

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

ekoukltd/version
================

Take control over your Laravel app version

1.3.1(3y ago)04.5k↓100%MITPHPPHP &gt;=7.0

Since Nov 29Pushed 3y agoCompare

[ Source](https://github.com/ekoukltd/version)[ Packagist](https://packagist.org/packages/ekoukltd/version)[ RSS](/packages/ekoukltd-version/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (5)Versions (33)Used By (0)

Version
=======

[](#version)

### Take control over your Laravel app version

[](#take-control-over-your-laravel-app-version)

 [![](docs/screenshot.png)](docs/screenshot.png)

 [![Latest Stable Version](https://camo.githubusercontent.com/c1842cc3c1556b17a12ff3fa34320a67354178bb0c5141931fd3397c86151559/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f707261676d6172782f76657273696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/pragmarx/version) [![License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](/antonioribeiro/version/blob/master/LICENSE.md) [![Code Quality](https://camo.githubusercontent.com/f3a5c8eaf40b7a98e96fe71526f5f47f15e95c323d6526be10d828b26cbbe3a1/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f616e746f6e696f7269626569726f2f76657273696f6e2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-version.com/g/antonioribeiro/version/?branch=master) [![Build](https://camo.githubusercontent.com/7e0bf9d34a2e37be826444990c5795fe8bb4243a4423951969ae0a0892817fc6/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f6275696c642f672f616e746f6e696f7269626569726f2f76657273696f6e2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-version.com/g/antonioribeiro/version/?branch=master)

 [![Coverage](https://camo.githubusercontent.com/49bad18e836bf317087126818bbaa59a10224bfc841de4aad9ba8672bbe72910/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f616e746f6e696f7269626569726f2f76657273696f6e2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-version.com/g/antonioribeiro/version/?branch=master) [![StyleCI](https://camo.githubusercontent.com/41a6e7989f92b492bc54a5ba89ceb06725aca8b884bf5b96f77e800ca868b0e9/68747470733a2f2f7374796c6563692e696f2f7265706f732f3131323234343436352f736869656c64)](https://styleci.io/repos/112244465) [![Downloads](https://camo.githubusercontent.com/117e49174194157a9adc27266503ac4223929902996f894a3810227afbc35eaa/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f707261676d6172782f76657273696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/pragmarx/version)

Description
-----------

[](#description)

This package is a Laravel (5.5+) utility which helps you keep and manage your application version, increment version numbers (major, minor, patch, commit), and can also use your last commit hash.

#### The end results of this package are:

[](#the-end-results-of-this-package-are)

- Print a version on a page.
- Print it in the console, via an Artisan command.

#### Full SemVer compatibility

[](#full-semver-compatibility)

This package is able to parse a SemVer version:

```
v2.0.1-alpha.1227

```

And translate it to be used as:

```
label: v
major: 2
minor: 0
patch: 1
prerelease: alpha
buildmetadata: 1227
commit: 49ffe2

```

You can use the format function to rewrite and show it in your app, for instance, as:

```
MyApp version 2.0.1 - alpha 1227 (commit 49ffe2)

```

#### Some use cases for those results could be:

[](#some-use-cases-for-those-results-could-be)

- Make sure a rollback was successful.
- Know if an update reached all servers.
- Check if a user is looking at the last version of your app.
- Verify if is Travis CI testing the version it is supposed to be testing.
- You simple love to version your stuff, and you like to see them in all your pages? That's cool too. :)
- What's your use case? [Tell us!](https://github.com/antonioribeiro/version/issues/new)

Features
--------

[](#features)

### Easily control you app version using a YAML config file

[](#easily-control-you-app-version-using-a-yaml-config-file)

```
version:
    current:
        major: 1
        minor: 0
        patch: 0
        format: '{$major}.{$minor}.{$patch}'
    commit:
        mode: number
        number: 701036
```

### Use your git commit as your app commit hash/number

[](#use-your-git-commit-as-your-app-commit-hashnumber)

Configure it

```
commit:
    mode: git-local
```

And you may have an output like this

```
MyApp version 1.0.0 (commit a9c03f)

```

Or just use an incremental commit hash/number:

```
commit:
    mode: number
    number: 701036
```

To get

```
MyApp version 1.0.0 (commit 701036)

```

### Easily increment your version numbers, using Artisan commands

[](#easily-increment-your-version-numbers-using-artisan-commands)

```
php artisan version:commit
```

Which should print the new version number

```
New commit: 701037
MyApp version 1.0.0 (commit 701037)
```

Available for all of them:

```
$ php artisan version:major
$ php artisan version:minor
$ php artisan version:patch
$ php artisan version:build
```

### The output format is highly configurable

[](#the-output-format-is-highly-configurable)

You can configure the :

```
format:
  version: "{$major}.{$minor}.{$patch}"
  full: "version {{'format.version'}} (commit {$commit})"
  compact: "v{{'format.version'}}-{$commit}"
```

Those are the results for `full` and `compact` formats

```
MyApp version 1.0.0 (commit 701037)
MyApp v1.0.0-701037

```

It gives you access to dynamic methods:

```
Version::compact()
```

And should you create a new one:

```
format:
  awesome: "awesome version {$major}.{$minor}.{$patch}"
```

It will also become callable:

```
Version::awesome()
```

### A Facade is available

[](#a-facade-is-available)

```
Version::version() // 1.2.25

Version::commit() // 703110

Version::major() // 1

Version::minor() // 2

Version::patch() // 25

Version::format('full') // version 1.0.0 (commit 703110)

Version::full() // version 1.0.0 (commit 703110) -- dynamic method

Version::format('compact') // v.1.0.0-703110

Version::compact() // v.1.0.0-703110 -- dynamic method
```

### Instantiating it

[](#instantiating-it)

If you prefer not to use the Façade:

```
dd(
    Version::format()
);
```

The best ways to instantiate it are:

A simple PHP object instantiation:

```
$version = new \PragmaRX\Version\Package\Version();

dd(
    $version->format()
);
```

Or to get an already instantiated Version object from the container:

```
dd(
    app(\PragmaRX\Version\Package\Version::class)->format()
);
```

But you have to make sure you [published the config file](/install)

### A Blade directive is also ready to be used in your views

[](#a-blade-directive-is-also-ready-to-be-used-in-your-views)

You can use this directive to render a full version format:

```
@version
```

Or choose the format:

```
@version('full')
@version('compact')
```

You can configure the directive name:

```
blade_directive: printversion
```

Then

```
@printversion('compact')
```

### Git tags

[](#git-tags)

You can use your git tags as application versions, all you need is to set the version source to "git":

```
version_source: git
```

And if you add a commit hash/number to your tags:

```
$ git tag -a -f v0.1.1.3128
```

Version will use it as your app commit hash/number

### Matching other version (git tags) formats

[](#matching-other-version-git-tags-formats)

You probably only need to change the git version matcher

```
git:
  ...
  version:
    matcher: "/[V|v]*[ersion]*\\s*\\.*(\\d+)\\.(\\d+)\\.(\\d+)\\.*(\\w*)/"
```

So let's say you tag your releases as

```
2017120299
YYYYMMDD##

```

You can change your matcher to

```
git:
  version:
    matcher: "/(\d{4})(\d{2})(\d{2})(?:\d{2})/"
```

And remove dots from your formats:

```
format:
  compact: "v{$major}{$minor}{$patch}-{$commit}"
```

### Using the current application version in your code

[](#using-the-current-application-version-in-your-code)

Here's a community example on how to send the app version number when logging an exception to Bugsnag:

```
