sebastian/version
Library for deriving a PHP project’s version from Git. Provide a release string and project path; Version::asString() returns the release, a -dev suffix, or git describe output (tags/commits) depending on repo state and release format.
Start by installing the package as a dev dependency since version reporting is typically used in tooling—not runtime application logic:
composer require --dev sebastian/version
Then create a simple CLI script (e.g., bin/version) to expose your project’s version:
<?php
require __DIR__ . '/../vendor/autoload.php';
use SebastianBergmann\Version;
$version = new Version('1.0.0', __DIR__ . '/..');
echo $version->asString() . PHP_EOL;
Run it with php bin/version. On a Git-tracked repo with tags, it outputs e.g. 1.0.0-17-g00f3408; without Git, it falls back cleanly to 1.0.0-dev if $release is X.Y.
php app:version command in Laravel that injects version info (use a config or .env-backed $release for explicit control)./internal/version (with authentication!) for deployment verification—append Git commit hash for traceability.$release from CI variables (e.g., getenv('CI_COMMIT_TAG') ?: 'X.Y') to ensure version strings reflect the actual build context.$release in config/version.php (populated by CI) to avoid hardcoding and support rollback-safe versioning.git describe fails silently in shallow clones (common in CI). Always run git fetch --depth=10 --tags before version generation if using GitHub/GitLab Actions.7.0.0+ requires PHP 8.4 (which doesn’t exist yet)—use ^6.0.0 for PHP 8.0–8.3. Verify compatibility via composer show sebastian/version.asString() returns $release (e.g., 1.0) or 1.0-dev—log a warning if suffixes like -dev appear in production.git describe --tags manually in your repo root to sanity-check expected output—mismatches often stem from detached HEADs or missing annotated tags.SebastianBergmann\Version to strip Git metadata for production releases (e.g., return only semantic version) while preserving dev build richness.How can I help you explore Laravel packages today?