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

Chitrasen's avatar

How to clear config cache data from route in laravel 5.5

I have a situation where i need to clear my config cache data from my project, i don't have access to server to run commands, so i want to run artisan commands from route, i kept clear cache in route its working fine but not working for config:cache from route, below is my code

Route::get('cache_config', function () { \Artisan::call('config:cache'); dd("Config cache is cleared"); });

Can anyone help me how to do this, why its not working, its not clear my config cache data

0 likes
10 replies
Nakov's avatar

@chitrasen the command is not config:cache to clear the config, but it is config:clear instead.

Chitrasen's avatar

Nakov config:cache not clearing my config cache data, i tried from command line, but config:cache clearing my config cache data. In documentation they told to use these two commands to clear config cache

towhid's avatar
php artisan cache:clear;
php artisan config:clear;
php artisan route:clear;
php artisan view:clear;

if you want you can clear , i hope everything will be fine . thank you @chitrasen

1 like
Chitrasen's avatar

Thank you @towhid, but i want to run commands from route as i mentioned in my code, i dont have permission to run commands from server, all commands working properly from route but config:cache command not working

Sinnbeck's avatar

If you want to call artisan commands from code you can do it like this

Artisan::call('config:clear');

I notice you keep mentioning using config:cache to clear cache. Be aware that it clears and then sets the cache again.

Chitrasen's avatar

Hi Sinnbeck, Artisan::call('config:clear'); not working, actually i want to change my env file values without restarting the server, for that i am doing these things, I kept env values in app.php and calling them into my controller, so i want to clear config cache to reflect those values in my controller. Is there any other way to achieve this

Sinnbeck's avatar

So you are changing the .env file using PHP or ? Be aware that if you never cache your config, you will never have to clear it.

Chitrasen's avatar

Sinnbeck, yes i am using php to edit my env file values, and i am not caching my config, i am clearing it manually

Sinnbeck's avatar

Again. No need to clear anything. If you dont cache it, then dont clear it.

Please or to participate in this conversation.