php Laravel 5.5 Blade route() 参数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/48530060/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel 5.5 Blade route() parameter
提问by jschubert
Can I add a parameter which I can use in a blade template, and which doesn't appear in the url?
我可以添加一个参数,我可以在刀片模板中使用它,但它不会出现在 url 中吗?
route("Home", ['id' => 1]);
@if(isset($id))
//Do something
@endif
采纳答案by jschubert
I solved it. instead of route()
is used redirect()
我解决了。而不是route()
使用redirect()
redirect()->with(['id' => 1]);
回答by Nole
I had need to create route in view and to send parameter that route.
我需要在视图中创建路由并发送该路由的参数。
I did it this way:
我是这样做的:
{{route('test', $id)}}
回答by Andrew
You can pass in parameters just like that yes, but they will be included in the url:
您可以像这样传递参数,是的,但它们将包含在 url 中:
https://laravel.com/docs/5.5/routing#named-routes
https://laravel.com/docs/5.5/routing#named-routes
If the named route defines parameters, you may pass the parameters as the second argument to the route function. The given parameters will automatically be inserted into the URL in their correct positions:
如果命名路由定义了参数,您可以将参数作为第二个参数传递给路由函数。给定的参数将自动插入到 URL 的正确位置:
Route::get('user/{id}/profile', function ($id) {
//
})->name('profile');
$url = route('profile', ['id' => 1]);
To pass parameters without including them in the url you will need to add the parameters in the controller/router method, and not withing the route()
method. Eg:
要传递参数而不将它们包含在 url 中,您需要在控制器/路由器方法中添加参数,而不是在route()
方法中。例如:
Route::view('/welcome', 'welcome', ['name' => 'Taylor']);