Laravel Artisan - 重新加载 .env 变量或重启框架
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40346250/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel Artisan - reload .env variables or restart framework
提问by Giedrius
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.
我正在尝试编写一个命令作为构建项目的快速入门。该命令要求输入数据库详细信息,然后更改 .env 文件。问题是该命令之后需要执行一些数据库查询,但不会重新加载 .env 变量。
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?
我的问题是,有没有办法重新加载或覆盖 .env 变量运行时。如果没有,有没有办法来调用另一个工匠命令新鲜,所以框架白手起家一遍吗?
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.
在我的命令中,我尝试$this->call('build:project')
在我的实际命令中执行,但即使在第二次调用中,变量也不会重新加载。
Is there a way to achieve this without making the user manually call multiple commands?
有没有办法在不让用户手动调用多个命令的情况下实现这一点?
Thanks!
谢谢!
回答by Alexey Mezenin
Laravel uses config files which take data from .env
file. So, what you can do is to override configuration valuesat runtime:
Laravel 使用从.env
文件中获取数据的配置文件。因此,您可以做的是在运行时覆盖配置值:
config(['database.default' => 'mysql']);
回答by midodesign
i had the same problem with reloaded .env variables, and i fixed it with this command line which allow you to clear the configuration :
我在重新加载 .env 变量时遇到了同样的问题,我用这个命令行修复了它,它允许你清除配置:
php artisan config:clear
Hope that helped. Regards.
希望有所帮助。问候。
回答by Mladen Nikolic
Try to clear cache it helped me (couldn't ssh into the server)
尝试清除缓存它对我有帮助(无法 ssh 进入服务器)
Is there a {app route}/bootstrap/cache/config.php file on the production server? Delete it.
生产服务器上是否有 {app route}/bootstrap/cache/config.php 文件?删除它。
This helped me
这帮助了我