top of page

4 Ways to Get the Laravel Version

Updated: Mar 2, 2023

Laravel is a popular PHP web application framework that provides various features and functionalities for developing web applications. It is important to know the version of Laravel being used in your project for several reasons, such as bug fixes, security updates, and compatibility with other libraries and packages. In this article, we will discuss 4 different methods to get the Laravel version in your project.


Method 1: Using the Laravel command-line interface (CLI)

Laravel provides a command-line interface (CLI) that can be used to get the version of the Laravel framework. To get the version of Laravel, open your terminal or command prompt and run the following command:

php artisan --version

Output:

Laravel Framework 8.37.0

The above command will display the Laravel version on the command-line interface.


Method 2: Using the PHP constant

Laravel provides a PHP constant named "Laravel::VERSION" that can be used to get the Laravel version in your PHP code. To get the Laravel version using the PHP constant, use the following code:

use Illuminate\Foundation\PackageManifest;
echo PackageManifest::VERSIONS['laravel/framework'];

Output:

8.37.0

The above code uses the "PackageManifest" class to get the Laravel version using the "VERSIONS" constant.


Method 3: Using the composer.json file

The Laravel version can also be obtained by looking at the "composer.json" file in your Laravel project. To get the Laravel version from the "composer.json" file, use the following code:

$json = json_decode(file_get_contents(base_path('composer.json')), true);
echo $json['require']['laravel/framework'];

Output:

8.37.*

The above code reads the "composer.json" file and extracts the Laravel version from the "require" section.


Method 4: Using the Illuminate\Foundation\Application class

The Laravel version can also be obtained using the "Illuminate\Foundation\Application" class. To get the Laravel version using this method, use the following code:

$app = app();
echo $app->version();

Output:

8.37.0

The above code uses the "app()" function to get an instance of the "Illuminate\Foundation\Application" class and then calls the "version()" method to get the Laravel version.


Conclusion:

In this article, we have discussed 4 different methods to get the Laravel version in your project. You can use any of these methods to get the Laravel version in your PHP code or on the command-line interface. Knowing the Laravel version can help you keep your project up-to-date with bug fixes, security updates, and compatibility with other libraries and packages.

0 comments

Commentaires


bottom of page