在Laravel中修改路由域为IP地址


Change Route Domain to IP address in Laravel

我想知道如何将laravel的基础url更改为IP地址。我使用localhost,而不是http://localhost,我希望它是http://127.0.0.1。更改app/config/app.php的URL属性并不是解决方案,因为该设置仅用于控制台命令(artisan)。

我想要达到的是使这个链接值:

{{ HTML::style('assets/images/favicon.ico', array('rel' => 'icon', 'type' => 'image/x-icon')); }}

:

<link rel="icon" type="image/x-icon" media="all" href="http://local/apps/myapp/public/assets/images/favicon.ico">

:

<link rel="icon" type="image/x-icon" media="all" href="http://127.0.0.1/apps/myapp/public/assets/images/favicon.ico">

至少有两种方法可以覆盖基URL。直接在刀片视图中:

{{ HTML::style('http://127.0.0.1/assets/images/favicon.ico'); }}
或者在你的routes.php中,你可以访问URL facade,它提供了forceRootUrl方法:
URL::forceRootUrl('http://127.0.0.1');
这样,

就可以全局声明基URL,方法是把它放在routes.php:

的顶部。
URL::forceRootUrl('http://127.0.0.1'); // all your routes are declared below this point.
Route::get('/', function()
{
    return View::make('hello');
});

甚至是本地的单个路由:

Route::get('/', function()
{
    URL::forceRootUrl('http://127.0.0.1');
    return View::make('hello');
});