The 5 best ways to check the Laravel version of your project

Introduction

When developing a new project or making new functionality for an existing project, developers need to know what the current version of Laravel is. Ensuring compatibility of various dependencies, stability of work and set of functions of the whole project depends on the version of the framework.

With the development of the framework and the release of new versions increases the core with a set of features and fixes pre-existing problems.

If possible, try to keep the Laravel core up to date. This will help you to always be using the latest features of leading developers and will save you from the problem of updating several versions at a time, which will carry a lot of potential problems when moving from version to version.

When creating or finalizing projects, it is important to keep track of the version of PHP, composer dependencies and the version of the Laravel framework itself. But in order to do this and not experience problems, in this article we will look at all possible methods of checking the Laravel version, from the programmatic method to the command line, from the fastest to the most practical ways to get the version.

Usinging the Laravel Artisan Command

A simple way to check the Laravel version is to check via the command line (CLI). This method serves only one purpose - to show the current version of Laravel, and is therefore the most practical to use.

Perform the following steps:

  • Open a command prompt or terminal.

  • Navigate to the directory of your Laravel project.

  • Run the command php artisan --version or php artisan -V.

  • The console will display information about the current version

Using the Laravel About Command

The Laravel developers have taken care and provided the ability to quickly get information about the project from the console line using the Artisan shell.

The command gives a detailed answer not only about the Laravel version, but also about PHP and composer versions, as well as information about the runtime environment, configuration and cached data. A good and fast solution for quick familiarization with the project.

The about command from Artisan: php artisan about , this command became available in Laravel 9.21 and will not be available in earlier versions.

Using the Laravel About Command

Check Laravel version via Composer

Composer, being a dependency manager for PHP, knows exactly what packages are installed. Laravel itself is partly a package - laravel/framework. So you can manage packages and take advantage of all the features of Composer, one of which is checking the version of packages via composer show. To check Laravel version via composer follow the steps:

  • Open a working terminal

  • Navigate to the directory with Laravel project

  • Run the command composer show -lo laravel/framework.

  • By passing the package name to composer you will see detailed information about Laravel, including its version.

name : laravel/framework
descrip. : The Laravel Framework.
keywords : framework, laravel
versions : * v9.52.16
latest : v10.48.2

Composer will help you find out the Laravel version, as well as other dependencies and their respective versions.

Check Laravel version via composer.json or composer.lock file

The composer.json and composer.lock files are the main and key files when working with composer, they store all version settings and their dependencies on the project. The composer.json file stores the minimum Laravel version to install the project.

When you run the composer install command, the package manager references the dependency versions from composer.json and writes the exact version with all metadata to the composer.lock file, and downloads the package itself to the vendor directory.

By saving all the project and Laravel information in composer, you can find the Laravel version information in the composer.json file . Find the "laravel/framework" dependency under "require".

  "require": {
    "php":"^8.0.2",
    "laravel/framework": "^9.19",
}

The composer.lock file offers more detailed information. Checking the Laravel version via the file system allows you to manually check the Laravel version by referring to metadata information.

File composer.lock

This method is not recommended, as it requires an understanding of the framework's file structure and contains a lot of additional information that can be confusing for beginners.

Programmatically check Laravel version via source code

Many programmers in the PHP world know that Laravel is built on Dependency injection (DI) which contains a container - Illuminate\Foundation\Application . This class contains the current version of Laravel. The version can be found in the VESRION constant

class Application extends Container implements ApplicationContract, CachesConfiguration, CachesRoutes, HttpKernelInterface
{
    use Macroable;

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

This constant can be obtained programmatically using app() helper function or App facade.

\Illuminate\Support\Facades\App::version(); // 9.52.16.

app()->version() // 9.52.16

By adding the ability to get the version programmatically, you can react on the fly to changes from Laravel.

Conclusion

Anyone can check the version, regardless of experience, because there are many ways, everyone will find a suitable one. This knowledge is necessary for everyone, no matter how it is used. Each method allows you to better understand the file system or the software part of the project and helps you to always be aware of the current version of Laravel.

Regularly analyzing and updating Laravel core versions will provide the project with the latest features of the framework and ensure version compatibility with other dependencies.

Most opensource solutions written for Laravel are focused on the latest stable version and update their code as the framework is updated. So be prepared to lose support for updates to most related packages if you don't update.

Similar Articles