问题
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