使用可选参数获取 Laravel 路由
我想知道是否可以在 Laravel 中获取带有可选参数的完整 url/路径。
在 web.php 中,我有这个:
Route::get('/blabla/{var1}/blabla/{var2?}', [Controller::class, 'function'])->name('myroute');
并想获得完整的 url/路径:
echo route('myroute', 'var1', 'var2');
但只出现“var1”。怎么会?手册中没有示例。
I was wondering if it's possible to get the full url/path in Laravel with a optional parameter in it.
In web.php I have this:
Route::get('/blabla/{var1}/blabla/{var2?}', [Controller::class, 'function'])->name('myroute');
And want to get the full url/path with this:
echo route('myroute', 'var1', 'var2');
But only 'var1' appears. How come? In the manual there are no examples.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
参数应该位于一个数组中,例如:
The parameters should be in an array like: