Check Laravel Version using several methods

Posted on

This article is focusing on checking the version of Laravel. Currently when this article is being written, Laravel is known as one of the most popular web-based framework using PHP as the language chosen to build web application.

As soon as the installation of Laravel has finished, the version installed can be checked in the command line using the following command :

php artisan --version

To be able to execute the above command in the command line, it must be done with the artisan utility available. One thing that can be done to get an artisan is create a new project based on Laravel.

user@hostname:/var/www/html/laravel-application# php artisan --version
Laravel Framework version 5.3.10
user@hostname:/var/www/html/laravel-application#

Another way which can be used to check the version of currently installed Laravel is by creating a simple page in the Laravel application.

Create a new controller in the command line using artisan tool as shown below :

user@hostname:/var/www/html/laravel-testing$ php artisan make:controller CheckLaravelVersion
Controller created successfully.
user@hostname:/var/www/html/laravel-testing$

The above command created a new controller and it affect the project with a new created controller file in /app/Http/Controllers. It can be checked by executing the ‘tree’ command as follows :

user@hostname:/var/www/html/laravel-testing# tree app/Http/Controllers/ -L 1
app/Http/Controllers/
├── Auth
├── CheckLaravelVersion.php
└── Controller.php
1 directory, 3 files 
user@hostname:/var/www/html/laravel-testing#

As shown above, there is a new file named CheckLaravelVersion.php inside app/Http/Controllers from the root directory of Laravel-based project called ‘laravel-testing’.

user@hostname:/var/www/html/laravel-testing$ cd app/Http/Controllers/
user@hostname:/var/www/html/laravel-testing/app/Http/Controllers$ ls
Auth  CheckLaravelVersion.php  Controller.php DatabaseController.php  
user@hostname:/var/www/html/laravel-testing/app/Http/Controllers$ vim CheckLaravelVersion.php

The name of the new file in app/Http/Controllers has a same name of the name given as a parameter when artisan tool used to create a new controller. Check the new created file in app/Http/Controller and start to use any text editor available by editing the new created controller file with some additional content so it can be modified to view the Laravel’s current version used.

Original Content :

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
class CheckLaravelVersion extends Controller
{
//
}

Additional Content :

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
class CheckLaravelVersion extends Controller
{
//
public function index()
{
$laravel = app();
echo "Laravel Version : ".$laravel::VERSION;
}
}

As shown in the above snippet code inside the new created controller file named CheckLaravelVersion.php, the content of the file is added with a new function called index with some few lines to get the Laravel version shown in the following snippet code :

$laravel = app();
echo "Laravel Version : ".$laravel::VERSION;

To be able to view the function of the controller which has already created and edited is being executed via web browser available, register it to Laravel’s route provider.

In Laravel 5.3.10 :

In this version, Laravel route provider exist in web.php located in routes folder inside the Laravel project root directory. It is shown as follow :

user@hostname:/var/www/html/laravel-testing# tree routes/ -L 1
routes/
├── api.php
├── console.php
└── web.php
0 directories, 3 files
You have new mail in /var/mail/root
user@hostname:/var/www/html/laravel-testing#

Use any available text editor to add the following line to web.php :

Route::get('laravel-version','CheckLaravelVersion@index');

But in Laravel which has the lower version of Laravel 5.3.10, the location of Laravel router provider is in app/Http, as shown below :

user@hostname:/var/www/html/laravel-test# php artisan --version
Laravel Framework version 5.2.41
user@hostname:/var/www/html/laravel-test# cd ..
user@hostname:/var/www/html# cd laravel-test
user@hostname:/var/www/html/laravel-test# tree app/Http/ -L 1
app/Http/
├── Controllers
├── Kernel.php
├── Middleware
├── Requests
└── routes.php
3 directories, 2 files
root@soulreaper:/var/www/html/laravel-test#

As shown in the above output command, in Laravel version 5.2.41, the Laravel router provider is located in app/Http from the root folder of Laravel project named ‘laravel-test’ on the above context.

After editing routes.php by adding the line for registering URL address routing to display URL for viewing Laravel current version, try to display the final output in the web browser by typing and executing additional URL /laravel-testing shown as follows :

One thought on “Check Laravel Version using several methods

Leave a Reply