Laravel Artisan - reload .env variables or restart the framework

I am trying to write a command as a quick start to create a project. The command prompts for database input, and then modifies the .env file. The problem is that the team needs to make some database queries after that, but the .env variables are not reloaded.

My question will be, is there a way to reload or override the current .env variable environments. And if not, is there a way to call another Artisan command again, so do the frame bootstraps again?

In my command, I tried to execute $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 forcing the user to manually invoke multiple commands?

Thank!

+4
source share
2 answers

Laravel uses configuration files that take data from a file .env. So what you can do is override the configuration values at runtime:

config(['database.default' => 'mysql']);
+5
source

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

php artisan config:clear

Hope this helps. Regards.

+1
source

Source: https://habr.com/ru/post/1659428/


All Articles