laravel 使用 URL::action() 时如何更改域

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

How do I change the domain when using URL::action()

laravellaravel-4

提问by bkubs

I am trying to duplicate something that was available in Laravel 3. I want to be able to specify an alternate domain name for a route. For example, I have a route that produces the following with this code:

我正在尝试复制 Laravel 3 中可用的内容。我希望能够为路由指定备用域名。例如,我有一个使用此代码生成以下内容的路线:

URL::action('DashboardController@something')
// Produces: http://somedomain.com/dashboard/something

I want to be able to specify a different domain. This used to be in the config/application.php file as 'url'. This no longer works in L4.

我希望能够指定不同的域。这曾经在 config/application.php 文件中作为“url”。这不再适用于 L4。

Is there a way to specify a base url to use whenever a URL is being constructed?

有没有办法在构造 URL 时指定要使用的基本 URL?

回答by Felix

Laravel 4 uses the Domain specified in the HTTP Request Header Field Host, e.g. Host: http://foo.dev.

Laravel 4 使用 HTTP 请求头字段中指定的域Host,例如Host: http://foo.dev.

If you want a different domain name, try something like this:

如果您想要不同的域名,请尝试以下操作:

Route::group(array('domain' => 'bar.dev'), function()
{
    Route::controller('home', 'HomeController');
});

Now URL::action('HomeController@getWelcome');returns https://bar.dev/home/welcomeinstead of https://foo.dev/home/welcome

现在URL::action('HomeController@getWelcome');返回https://bar.dev/home/welcome而不是https://foo.dev/home/welcome

回答by Hauthorn

The location of the "app"-directory is defined in: \bootstrap\paths.php The default location of config file is now: \app\config\app.php

“app”目录的位置定义在:\bootstrap\paths.php 配置文件的默认位置现在是:\app\config\app.php

Depending on your setup, it should be around line 29 in app.php.

根据您的设置,它应该在 app.php 中的第 29 行左右。

Look for:

寻找:

'url' => 'http://somedomain.com',

And change this to whatever suits your website.

并将其更改为适合您网站的任何内容。