Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Artisan - reload .env variables or restart framework

I'm trying to write a command as a quickstart to build a project. The command asks for input for database details and then changes the .env file. The problem is that the command needs to do some Database queries afterwards, but the .env variables are not reloaded.

My question would be, is there a way to reload or override .env variables runtime. And if not, is there a way to call another Artisan command freshly, so framework bootstraps again?

In my command I tried doing $this->call('build:project') in my actual command, but even in the second call the variables are not reloaded.

Is there a way to achieve this without making the user manually call multiple commands?

Thanks!

like image 329
Giedrius Avatar asked Oct 31 '16 16:10

Giedrius


2 Answers

i had the same problem with reloaded .env variables, and i fixed it with this command line which allow you to clear the configuration :

php artisan config:clear

Hope that helped. Regards.

like image 107
midodesign Avatar answered Oct 09 '22 04:10

midodesign


Laravel uses config files which take data from .env file. So, what you can do is to override configuration values at runtime:

config(['database.default' => 'mysql']);
like image 20
Alexey Mezenin Avatar answered Oct 09 '22 03:10

Alexey Mezenin