Skip to content

Instantly share code, notes, and snippets.

@julienbourdeau
Created October 22, 2022 08:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save julienbourdeau/9f6e3bb520e7af3efad654d824dcde58 to your computer and use it in GitHub Desktop.
Save julienbourdeau/9f6e3bb520e7af3efad654d824dcde58 to your computer and use it in GitHub Desktop.
Show current Git hash (as version) with Laravel Blade component
<?php
namespace App\View\Components\Admin;
use Illuminate\Support\Facades\Cache;
use Illuminate\View\Component;
class GitDetails extends Component
{
const REPO = 'julienbourdeau/julienbourdeau.com';
public function render()
{
$hash = Cache::remember('currentGitHash', 3600, fn() => exec('git rev-parse HEAD'));
$url = sprintf('https://github.com/%s/tree/%s', self::REPO, $hash);
return view('components.admin.git-details', [
'hash' => $hash,
'url' => $url,
]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment