我正在开发我开发的另一个网站将使用的 API 服务.因此,在本地构建和测试时,显然我希望站点的两个本地副本都能正常工作.但是,它似乎混淆了 environment
变量.
I am developing an API service that another site I've developed will be using. So locally when building and testing, obviously I want both local copies of the site to work. However, it seems to mix up the environment
variables.
例如:
站点 A
有 APP_URL=http://a.local
站点 B
有 APP_URL=http://b.local
Site A
代码向 http://b.local/test 发送 GET
请求(使用 Guzzle
)
Site B
中的 /test
端点只是简单地转储出 dump(env('APP_URL'))
Site A
检索到的结果是 "http://a.local"
http://b.local"
Site A
has APP_URL=http://a.local
Site B
has APP_URL=http://b.local
GET
Request (using Guzzle
) from Site A
code to http://b.local/test
/test
endpoing in Site B
simply dumps out dump(env('APP_URL'))
Site A
is "http://a.local"
"http://b.local"
所以 Site B
中的代码使用从 Site A
加载的环境变量运行.这是一个问题,因为 Site B
无法访问正确的数据库,它正在尝试使用 Site A
的数据库.
So the code in Site B
is running with environment variables loaded from Site A
. This is an issue as Site B
cannot access the correct database, it's trying to use the Site A
's database.
这是我的本地设置(Win10 + WAMP)、PHP 设置、Laravel 设置的问题吗?
Is this an issue with my local setup (Win10 + WAMP), PHP settings, Laravel settings?
我也遇到了这个问题,提到了这里.它的解决方案是在两个项目中运行 php artisan config:cache 以缓存 .env 文件中的配置或修补 这里.
I also encountered this issue, and it is mentioned here. The resolution for it is to run php artisan config:cache in both projects to cache configuration from .env files or patch the code from here.
这篇关于WAMP Laravel - 将 API 请求从一个本地站点发送到另一个站点会混淆环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!