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

空扰寡人 提交于 2019-12-07 14:23:06

问题


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:

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.

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


回答1:


Laravel 4 uses the Domain specified in the HTTP Request Header Field Host, e.g. 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/welcome instead of https://foo.dev/home/welcome




回答2:


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

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

Look for:

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

And change this to whatever suits your website.



来源:https://stackoverflow.com/questions/16948595/how-do-i-change-the-domain-when-using-urlaction

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!