How to get the application name in laravel?

Stefan Izdrail

Founder & Senior Architect · 2026-06-29

Laravel Company
Title: Accessing the Laravel Application Name Programmatically Body: One of the many benefits of using Laravel is its flexibility, allowing you to define various configurations for your application. In this post, we will focus on understanding how to fetch the Laravel application name programmatically. To start with, let's learn about the different ways to set and get the application name in Laravel. 1. Setting the Application Name using Artisan: To begin, you can utilize the artisan command line interface (CLI) to set the application name. Here's how it works:
php artisan app:name xyz
As we see in this example, by running the given command, you will successfully set your application name as 'xyz'. This is a flexible option that provides immediate control over your application's name. It also gives you freedom to change it if needed later on. 2. Accessing the Application Name Programmatically: After setting the application name through the artisan command, how can we fetch its value in our Laravel application? We have two ways to achieve this. a) Using Config File: Laravel has a config folder that contains multiple configuration files for your project. One of these files is 'app.php'. In this file, you will find an array titled 'application' containing the application name as a key-value pair.
return [
    'application' => [
        'name' => env('APP_NAME', 'Laravel'),
    ],
];
To get the application name in your Laravel code, simply call this setting:
$appName = config('application.name');
This is a convenient way to access your app's name when you need it in your project. b) Using Environment Variables: Another method involves using environment variables for storing the application name. You can set up an 'APP_NAME' environment variable with the desired value, which will be accessible throughout the Laravel application. Here is how this works:
export APP_NAME=xyz
To get the application name in your code:
$appName = env('APP_NAME');
This method allows you to easily change or customize the app's name without touching any of Laravel's core files. 3. Conclusion: By following these methods, you will have multiple options for storing and retrieving your Laravel application's name. The artisan command provides an immediate way to set the name, while configuring the 'app.php' file or using environment variables offers flexible control over this setting. Regardless of which approach you choose, make sure to stay organized, as proper organization can significantly improve code readability and maintainability in your Laravel projects. At https://laravelcompany.com/, we understand the power of organization and best practices in web development. We specialize in providing Laravel consulting services and custom web application development with a focus on client satisfaction and project success. To learn more about our offerings, visit us online at https://laravelcompany.com.