0

考虑以下示例:

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 辅助方法来获取适当且完整的 url、域和所有内容?

4

1 回答 1

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>

完毕!

于 2015-12-29T02:11:51.810 回答