Skip to content

Simplify Laravel Version Shell Function - #714

Closed
ryanjbonnell wants to merge 1 commit into
serversideup:release/webserver-improvements-and-fixesfrom
ryanjbonnell:laravel-version
Closed

ryanjbonnell wants to merge 1 commit into
serversideup:release/webserver-improvements-and-fixesfrom
ryanjbonnell:laravel-version

Conversation

@ryanjbonnell

Copy link
Copy Markdown
Contributor

This update simplifies the logic of determining the Laravel version by reading the version information directly from the Laravel framework source.

Summary

The previous method relied on using Laravel Artisan to print the version information and parse the output with sed, bootstrapping the whole application just to print one constant. The Artisan method can fail for reasons that have nothing to do with the version, such as a missing .env value or a broken service provider.

Laravel declares its version as a constant in vendor/laravel/framework/src/Illuminate/Foundation/Application.php, shown below for reference:

/**
 * The Laravel framework version.
 *
 * @var string
 */
const VERSION = '4.0.11';

This pattern goes back as far as Laravel 4.x — or possibly even later — and every release bumps the version in this location.

Artisan itself reads this information, so we can use it to “short circuit” the version lookup without booting the application framework.

The shell function now reads it directly with grep -F | cut, so it doesn't start PHP and doesn't need a regex.

Highlights

  • get_laravel_version(): reads the constant with grep -F "const VERSION" … | cut -s -d "'" -f 2. It prints the version, or prints an error naming the file and returns 1. cut -s makes every failure case (missing file, no constant, no quotes) produce an empty result, so a single [ -z ] check covers them all.
  • Cache removed: the INSTALLED_LARAVEL_VERSION cache is gone. It never worked, because every caller runs the function in $(…), a subshell, so the value was lost each time. A file read takes a few milliseconds, so no cache is needed.
  • Callers: the debug banner prints Laravel detected: vX.Y.Z only when the version can be read; otherwise the error explains why. The isolated-migrations warning shows unknown instead of an empty version.

I ran local end-to-end tests using both Debian and Alpine images and each detected the Laravel version correctly.

I realized these improvements while debugging startup failures in Laravel automations and wanted to contribute the changes I made during development back to the project.

@jaydrogers
jaydrogers deleted the branch serversideup:release/webserver-improvements-and-fixes October 8, 2026 17:28
@jaydrogers jaydrogers closed this Oct 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants