使用Laravel 4,您可以使用以下代码生成一个指向指定路由的URL
$url = route('route-name');
$url = app('url')->route('route-name');
$url = URL::to('route-name');是否有可能生成到指定路由的安全 URL (https)?
我知道当你设置它时,你可以“强迫”一条路线是安全的。
Route::get('route-name', array('https', function()
{
return 'Must be over HTTPS';
}));然而,“武力”(似乎?)意味着使基于http的浏览不可见的路由。路由方法/函数不了解这一点,仍然生成http URL。
为了澄清,我设置了一条这样的路线
Route::get('/stack-overflow', array('as'=>'route-name', function(){
}));这是一条具有stack-overflow路径和route-name名称的路由。我可以使用名称(route-name)生成明文route-name链接。我希望使用https路由名(而不是路径)生成一个安全的链接。我还希望生成的URL包含查询字符串参数
https://example.com/stack-overflow?foo=bar发布于 2014-08-16 18:00:48
你在找网址::安全。
URL::secure('absolute/path');
//generates https://domain.com/absolute/path有一个指定的路线:
URL::secure(URL::route('route-name'));发布于 2014-08-17 19:33:43
获取上面Razor的注释,您可以使用以下代码生成我在Laravel 4.2.8中寻找的安全的查询字符串参数URL
//first parameter is the configured route name, second is the list of
//query string parameters, the third parameter (`$absolute`), ensures
//the protocol and server is stripped from the return value (giving us /path/to/route
//vs. http://example.com/path/to/route
$url_path = URL::route('route-name',['foo'=>'bar'],false);
//with the URL path generated, we can use the secure URL generation to
//turn that path into an https url
$secure_url = URL::secure($url_path);https://stackoverflow.com/questions/25340763
复制相似问题