
How To Check Laravel Version: A Quick Guide
By Kez | 02 Sep 24
Laravel’s elegant simplicity and powerful features allow you to create beautiful, secure apps full of powerful functionality. If you’re maintaining an existing project or beginning to explore a new one, knowing the exact Laravel version it’s built on is crucial.
Knowing which current Laravel version your apps are using ensures compatibility with any major releases every year and minor and patch releases that occur as often as every week. If your apps (or client’s apps) aren’t using the minimum version required, updating them can cause more bugs than bug fixes.
Below, we’re going to explore a few methods of how to check the Laravel version on your apps using artisan commands and several other methods. Whether you are on the command line, deep inside the code, or exploring via the browser, we’ve got you covered!
How to Check The Laravel Framework Version
Using the Artisan Command
The most straightforward way to check the Laravel version on your Laravel applications is through the Artisan CLI, Laravel’s powerful command line interface.
Steps:
- Navigate to your Laravel project directory – Open your terminal and use `cd` to navigate to the root directory of your Laravel project.
- Run the version command:
php artisan –version
This command will output the Laravel version installed in your project, for example:
Laravel Framework 10.5.1
Why This Method?
PHP artisan version is quick and reliable. It provides an immediate answer without needing to dive deep into code files. Plus, it works even if your application isn’t fully configured (as long as Artisan is functional). So, for the quickest answer to your Laravel project’s version, use this artisan command.
Checking the `composer.json` File
Another method is to inspect the `composer.json` file. This file holds the metadata about your Laravel project, including the Laravel version.
Steps:
- Locate the `composer.json` file: This file is typically found in the root directory of your Laravel project.
- Open the file: Use any text editor (e.g., VS Code, Sublime Text, or even `cat` in the terminal).
- Look for the Laravel version:
“require”: {
“laravel/framework”: “^10.0”,
…
}
The version constraint (e.g., `^10.0`) indicates the Laravel version your project uses.
Why This Method?
It’s handy when you’re reviewing the project dependencies and want to see Laravel’s version alongside other packages. It’s especially helpful when you need to check compatibility with specific Laravel releases, security patches or to confirm if an app is using a specific version.
Inspecting the `Framework` File
All Laravel versions store version control information in a core file. So, you can check this file directly within the source code to confirm the current version of Laravel. Here’s how:
Steps:
- Navigate to the version file:
– The file is located at `vendor/laravel/framework/src/Illuminate/Foundation/Application.php`.
- Search for the version method:
– Inside the `Application.php` file, find the `version` method, which typically looks like this:
public function version()
{
return ‘10.5.1’;
}
This will display the exact version of Laravel being used.
Why This Method?
This boot method is ideal if you want to do an in-depth inspection or debugging session. It’s also helpful when you want to confirm the version without relying on the command line or if you are working within the codebase already.
Checking via the Web Browser
If you have access to the web interface of your Laravel application, you can quickly check the version using a custom route or by viewing the default error page.
Creating a Custom Route:
- Add a route in your `routes/web.php`:
Route::get(‘/version’, function() {
return app()->version();
});
- Visit the route: Open your browser and navigate to `http://your-laravel-app/version`.
This will return the Laravel version directly in your browser.
Viewing the Error Page:
If you trigger a 500 error or visit a non-existent route in a default Laravel installation (with debug mode enabled), you might see the Laravel version in the bottom-right corner of the error page.
Why These Methods?
Checking via a custom route is great when you want to allow non-technical team members to check the version easily. Useful when working on a client’s work in a hosted environment where you might not have SSH access, for example.
Using PHP Code Snippets
If you’ve already got your sleeves rolled up and are deep in the code or you’re looking to automate version checks, you can easily print the Laravel version using the PHP echo app.
Example:
echo app()->version();
This line of code can be added anywhere in your project (e.g. a controller, view, or console command) to output the Laravel version.
Why This Method?
It’s perfect for embedding within scripts or custom commands. Plus it’s really handy for automated logs or reporting systems.
Key Takeaways
Knowing the Laravel version of your application is essential for maintaining, upgrading, and extending your project. Whether you’re on the command line, inspecting files, or interacting with your application via a web browser, there’s a method for finding the Laravel version no matter where you are. Each method has its own use cases, so choose the one that best fits your current workflow.
Are you looking for lightning-fast web hosting for your Laravel applications? Nimbus is the answer! Our VPS can provide secure, quick and reliable hosting for all of your apps. Whether you’re managing 10 or 1,000, we have a hosting solution for you! Get in touch and see why Nimbus is the trusted partner of digital agencies and developers across the UK.