【发布时间】:2018-07-09 20:21:54
【问题描述】:
我可以添加一个参数,我可以在刀片模板中使用,并且不会出现在 url 中吗?
route("Home", ['id' => 1]);
@if(isset($id))
//Do something
@endif
【问题讨论】:
-
那个参数是从哪里来的?是从相关表到“家”吗?
标签: php blade laravel-5.5
我可以添加一个参数,我可以在刀片模板中使用,并且不会出现在 url 中吗?
route("Home", ['id' => 1]);
@if(isset($id))
//Do something
@endif
【问题讨论】:
标签: php blade laravel-5.5
【讨论】:
你可以像这样传入参数,但是它们会包含在 url 中:
https://laravel.com/docs/5.5/routing#named-routes
如果命名路由定义了参数,你可以将参数传递为 路由函数的第二个参数。给定的参数将 自动插入到 URL 的正确位置:
Route::get('user/{id}/profile', function ($id) {
//
})->name('profile');
$url = route('profile', ['id' => 1]);
要传递参数而不将它们包含在 url 中,您需要在控制器/路由器方法中添加参数,而不是使用 route() 方法。例如:
Route::view('/welcome', 'welcome', ['name' => 'Taylor']);
【讨论】:
我解决了。而不是route() 使用redirect()
redirect()->with(['id' => 1]);
【讨论】: