考虑以下示例:
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-helper方法来获得适当且完整的url、域和所有内容
我认为你应该说出你的路线。
此处:
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>
完成!