所需参数值中的路由问题-Laravel



路线代码

Route::get(
'/product-{name}', 
[
ProductDetailsController::class, "showProductDetailsMainForm"
]
)->name("showProductDetailsMainForm");

用法

<a href="{!! route('showProductDetailsMainForm', 'name' => 'hello') !!}">

错误详细信息

缺少[Route:showProductDetailsMainForm]所需的参数〔URI:产品-{name}〕

我遗漏了什么吗?

您应该使用route('showProductDetailsMainForm', ['name' => 'hello']);

尝试

Route::get(
'/product/{name}', 
[
ProductDetailsController::class, "showProductDetailsMainForm"
]
)->name("showProductDetailsMainForm");

可视

<a href="{{ route('showProductDetailsMainForm', ['name' => 'hello']) }}">

对于单个参数,您可以这样定义(不提及参数名称(:

{{ route('showProductDetailsMainForm', 'hello') }}

或者,提及参数名称:

{{ route('showProductDetailsMainForm', ['name' => 'hello']) }}

并将Route::get('/product-{name}',…更改为Route::get('/product/{name}',…

最新更新