簡體   English   中英

將路由域更改為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屬性不是解決方案,因為該設置僅用於控制台命令(工匠)。

我試圖獲得的是使此鏈接值:

{{ 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外觀 ,該外觀提供forceRootUrl方法:

URL::forceRootUrl('http://127.0.0.1');

這樣就可以通過將基本URL放置在您的route.php之上來全局聲明基本URL

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');
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM