Laravel 5 config/app.php url 设置

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30040151/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 16:59:38  来源:igfitidea点击:

Laravel 5 config/app.php url setting

laravellaravel-5

提问by Kevin Compton

This issue became apparent for me when using dynamic routes within scheduled emails. The email url's are built with this config setting which apparently is not setup to adjust to the server environment. I am using Forge for production. What is best practice for configuring this attribute? Would I add a variable to env files?

在预定的电子邮件中使用动态路由时,这个问题对我来说变得很明显。电子邮件 url 是使用此配置设置构建的,显然它没有设置为适应服务器环境。我正在使用 Forge 进行生产。配置此属性的最佳做法是什么?我会在 env 文件中添加一个变量吗?

Currently its set as follow:

目前它的设置如下:

'url' => 'http://localhost',

采纳答案by cyber8200

I use Forge as my production also. Everything works for me. I have my settings like this :

我也使用 Forge 作为我的产品。一切都对我有用。我有这样的设置:

In my config\app.php

在我的config\app.php

I set my 'url' => env('DB_HOST'),

我设置了我的 'url' => env('DB_HOST'),

DB_HOST: is just the IP Address to your server.

DB_HOST:只是您服务器的 IP 地址。

and that should match with your .envfile on your Production Server.

这应该与您.env的生产服务器上的文件匹配。

My .envlook something like this :

我的.env样子是这样的:

APP_ENV=production
APP_DEBUG=false
APP_KEY=******************

DB_HOST= http://12.23.29.122/
DB_DATABASE=db-name
DB_USERNAME=forge
DB_PASSWORD=**************

Hope this help !

希望这有帮助!

回答by manix

If your website will be not installed on other domain, then you can assign it via config file directly:

如果您的网站不会安装在其他域上,那么您可以直接通过配置文件进行分配:

'url' => 'http://localhost',

If your application will be installed/ran in different enviroments or domain you can set it via .env file:

如果您的应用程序将在不同的环境或域中安装/运行,您可以通过 .env 文件进行设置:

# .env file
APP_URL=http://localhost

回答by Yevgeniy Afanasyev

you have a number of options

你有很多选择

1) set config param on the fly in unit test

1)在单元测试中即时设置配置参数

config(['app.url' => 'https://my.com']);

2) configure it in phpunit.xml file once and for all

2)在phpunit.xml文件中一劳永逸地配置

<env name="APP_URL" value="my.com"/>

3) change the unittest env on the fly and recreate application in your unit test

3)动态更改单元测试环境并在单元测试中重新创建应用程序

$_ENV['APP_URL'] = 'my.com'; $this->refreshApplication();

$_ENV['APP_URL'] = 'my.com'; $this->refreshApplication();

4) setup the .env variable in the public function setUp(): voidof your unit test file before the parent::setUp();

4) 在public function setUp(): void你的单元测试文件中设置 .env 变量parent::setUp();

5) modifying your .env file is one of the options too

5) 修改你的 .env 文件也是选项之一

APP_URL=my.com