Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

kwebble's avatar

What is the standard way to declare the application name?

To be able to show the name of the application to users, that piece of information has to be stored somewhere. What is the standard way in Laravel to set the application name?

This is about the human readable form, not the PHP namespace.

0 likes
6 replies
bobbybouwmann's avatar

You can use a config for it if your site is one language or you can use a translation file for it

I will go through both.

For the config we need to add a new value to the config/app.php file or even create a new config file, that's up to you. This should be added like an array, so we can simply do this

// config/app.php

<?php 

return [

    'name' => 'My Application Name',    
    
    // The rest of the configs.
];

Now you can access the name like so in your code and your views

config('app.name'); //My Application Name'

// And for your view
<h1>{{ config('app.name') }}</h1>

Using a translation file is just as easy as the config file. You simply create a new config file and then add the following

// resources/lang/en/app.php

<?php 

return [

    'name' => 'My Application Name',

];

If the application language is set to 'en' you can access the value like so

trans('app.name');

Now for each other translation you just create the new name.

We already discussed the config part, but if you think your application name might change in the future, you can put it in an environment variable like so

// .env

APP_NAME=My Application Name

And you can put this in your config, so you can change it depending on the environment of the application (you might have multiple deployments, just as an example)

// config/app.php

<?php 

return [

    // We use the .env if it exists or display the default value
    'name' => env('APP_NAME', 'My Application Name'), 
    
    // The rest of the configs.
];
6 likes
kwebble's avatar

Thanks for the detailed answer. As I understand it this defines a custom property name in config/app.php.

I expected Laravel to have a standard way to declare the application name. Does that exist, or is a custom property required?

1 like
Swaz's avatar

Are you talking about setting the application namespace?

You can use php artisan app:name.

kwebble's avatar

@Swaz no, not the namespace, the name you would show to a user.

apothegm's avatar

If you're going to use APP_NAME in .env, you should surround it with quotes if it contains spaces.

5 likes

Please or to participate in this conversation.