我们有一个简单的路线定义如下:
// Home Route::get('/home', [ 'as' => 'home::index', 'uses' => 'IndexController@home' ]);
<a href="{{ route('home::index') }}">Home</a>
我们需要在呈现为HTTP或在某些情况下呈现为HTTPS路由的视图中强制我们的链接/路由。 http://host.domain/home 或 https://host.domain/home .
http://host.domain/home
https://host.domain/home
我们不能使用 URL::forceSchema("http") 或 URL::forceSchema("https") 因为我们需要在HTTP页面上强制使用HTTPS,而在HTTPS页面上强制使用HTTP。我们有一个多域应用程序。有些域通过HTTP运行,有些域通过HTTPS运行。到不同域/应用程序部分的链接可以放在任何地方。通过https运行的域不能通过http访问。在HTTP上运行的域无法通过HTTPS访问
URL::forceSchema("http")
URL::forceSchema("https")
如何强制将路由呈现为特定的超文本协议?
Laravel documentaion Illuminate\Routing\UrlGenerator getRouteScheme http https
Illuminate\Routing\UrlGenerator
getRouteScheme
http
https
Route::get('/home', [ 'as' => 'home::index', 'uses' => 'IndexController@home', 'http' ]);
Route::get('/home', [ 'as' => 'home::index', 'uses' => 'IndexController@home', 'https' ]);
route('home::index')