Introducing

How to check Laravel Version


Sometimes you need to know the exact version of your Laravel application. Luckily, there are multiple ways hot to check the version and you can use the one that fits your needs in a specific situation.

Check your Laravel version with artisan

Laravel comes with a command-line interface called Artisan.

Artisan provides a huge number of commands that help you manage and build your Laravel application.

In order to get your exact Laravel version you can just run the following command in the directory of your Laravel project:

php artisan --version

The output that you would get will look like this:

Laravel Framework 8.54.0

Get the Laravel version the app() helper

Every Laravel release has the version of the framework as constant in the Application.php file. You can access this constant via the app() helper.

app()->version()

If you don't want to create a /version route to get the version, you can use php artisan tinker to get into the tinker REPL and run it from there.

Displaying the Laravel version in a Blade template

If you want to check the current Laravel version but don't run code every time, you can also display the version in your admin system via Blade. You can either display it via the app() helper or create a Blade macro for it. Displaying via the helper works with a simple output:

The current Laravel version is {{ app()->version() }}

If you check the Laravel version often and need it in multiple views, it could be useful to have a Blade directive for it. Blade directives are placed in the boot method of the AppServiceProvider of your application and you can add this code to simply display the version in Blade templates with @laravelVersion


Blade::directive('laravelVersion', function () {
    return "<?php echo app()->version(); ?>";
});

If you want to learn more about Blade Directive head over here.

Conclusion

Those were just 3 quick was of checking your exact Laravel version.

Hope that this helps!

Categories:
Tags:
Laravel version