考虑以下示例:
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帮助方法获取适当且完整的网址,域名和所有内容?
答案 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>
完成!