4 Ways To Get The Laravel Version

there are four different ways to get the version number of any Laravel project. In this article, each of the different methods will be demonstrated.


Method 1 – Using php artisan

We can always rely on the trusty old php artisan command and in this case, we can too! Load up the command line at the projects root directory, and execute the following command –

php artisan --version

For example, this for my project outputs the following –

Laravel Framework 8.12.0


Method 2 – Checking the composer.json file

Yep, sat minding its own business, is the version of your Laravel project, right in the composer.json file.

You will locate the composer.json file in the root directory of your project, for example, myApp/composer.json.


In this file, you will see something like the following –

{
    "name": "laravel/laravel",
    "type": "project",
    "description": "The Laravel Framework.",
    "keywords": [
        "framework",
        "laravel"
    ],
    "license": "MIT",
    "require": {
        "php": "^7.3|^8.0",
        "fideloper/proxy": "^4.2",
        "fruitcake/laravel-cors": "^2.0",
        "guzzlehttp/guzzle": "^7.0.1",
        "laravel/framework": "^8.12",  <------- Your Laravel Version
        "laravel/tinker": "^2.0"
    },
.........

As pointed to within the code, the Laravel version can be seen alongside the “require” package of laravel/framework, in this case, it’s 8.12.


Method 3 – Using the global application helper class

Inside your controller or similar you can access the global Application class by using the following statement –

$version = app()->version();
dd($version); // outputs "8.12.0"


Method 4 – Opening the global application helper class file

This one you may have already guessed, but of course, when you can access a value from within a class, it’s got to be stored in the codebase.