如何使用url()获取域路由laravel 5.2

时间:2015-12-28 21:34:59

标签: php laravel routing subdomain laravel-5.2

考虑以下示例:

Route::group(['domain' => 'something.example.local'], function() {
    Route::get('scripts', 'SomethingController@scripts');
});

现在假设您已经在something.example.local/scripts,并且您将鼠标悬停在链接上:<a href="{{ url(/scripts) }}">hello world</a>您将看到something.example.local/scripts。大。

不要去example.local并做同样的事情:example.local/scripts ......那是错的。它应该说:something.example.local/scripts

如何使用laravel帮助方法获取适当且完整的网址,域名和所有内容?

1 个答案:

答案 0 :(得分:3)

  

我认为你应该说明你的路线。

下面:

Route::group(['domain' => 'something.example.local'], function() {
    Route::get('scripts', ['as' => 'route.name', 'uses' => 'SomethingController@scripts']);
});

a标记中:

<a href="{{ route('route.name') }}">hello world</a>

完成!