Skip to content

Instantly share code, notes, and snippets.

@breadthe
Last active December 28, 2022 10:31
Show Gist options
  • Save breadthe/ce6a815b295c485b4bd91c08a79e1bf2 to your computer and use it in GitHub Desktop.
Save breadthe/ce6a815b295c485b4bd91c08a79e1bf2 to your computer and use it in GitHub Desktop.
Display app git tag & commit hash in a Laravel app
// resources/views/app/version.blade.php
<div>
<span>{{ config('version.string') }}</span>
<span>&mdsh;</span>
<span>{{ config('app.env') }}</span>
<span>&mdash;</span>
<span>{{ 'Laravel ' . app()->version() }}</span>
<span>&mdash;</span>
<span>{{ app()->getLocale() }}</span>
<span>&mdash;</span>
<span>{{ 'PHP ' . PHP_VERSION }}</span>
</div>
<?php
// config/version.php
// Based on this tweet by @Xewl https://twitter.com/Xewl/status/1459219464369627144
$tag = exec('git describe --tags --abbrev=0');
if (empty($tag)) {
$tag = '-.-.-';
}
$hash = trim(exec('git log --pretty="%h" -n1 HEAD'));
$date = Carbon\Carbon::parse(trim(exec('git log -n1 --pretty=%ci HEAD')));
return [
'tag' => $tag,
'date' => $date,
'hash' => $hash,
'string' => sprintf('%s-%s (%s)', $tag, $hash, $date->format('d/m/y H:i'));
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment