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

SergioGregorutti's avatar

$config->set not working?

Hi all,

I'm using the Config facade to set and use global variables on my site and it's working fine, but I have a problem.

On the AppServiceProvider.php (boot method) Im doing this:

$config->set('world.name', 'Mundo Hurlingham');

And then on a controller Im trying to overwrite the value doing this:

$config->set('world.name', 'Test');
echo "Result: ".config('world.name').'.';

But the problem is that the config('world.name') result is always "Mundo Hurlingham". And then I use the value on a view an is still the old value.

How can I overwrite the value? Is there a way to do this? Maybe clearing the cache or something like that?

Thanks in advance!

0 likes
3 replies
etkimbia's avatar
Level 2

This works fine for me...

In AppServiceProvider->boot():

\Config::set('world.name', 'Mundo Hurlingham');

And then in a controller method:

\Config::set('world.name', 'Test');
echo "Result: ".config('world.name').'.'; // displays "Result: Test."
Snapey's avatar

Use the facade (as per @etkimbia) , or use the helper, as below;

config(['world.name' => 'Mundo Hurlingham']);

config(['world.name' => 'Test']);

echo config('world.name');
1 like

Please or to participate in this conversation.