Repository navigation
Simplify Laravel Version Shell Function - #714
Closed
ryanjbonnell wants to merge 1 commit into
Closed
ryanjbonnell wants to merge 1 commit into
ryanjbonnell wants to merge 1 commit into
Conversation
jaydrogers
deleted the branch
serversideup:release/webserver-improvements-and-fixes
October 8, 2026 17:28
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.envvalue 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: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 withgrep -F "const VERSION" … | cut -s -d "'" -f 2. It prints the version, or prints an error naming the file and returns 1.cut -smakes every failure case (missing file, no constant, no quotes) produce an empty result, so a single[ -z ]check covers them all.INSTALLED_LARAVEL_VERSIONcache 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.Laravel detected: vX.Y.Zonly when the version can be read; otherwise the error explains why. The isolated-migrations warning showsunknowninstead 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.