php - Laravel 7.18.0 | [Route: category] 缺少必需的参数
问题描述
我的索引文件:
@foreach ($categories as $category)
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title"><a href="{{ route('category', app()->getLocale(), $category->name) }}">{{ $category->name }}</a></h4>
</div>
</div>
@endforeach
我的路线文件:
Route::prefix('/{language}')->group(function () {
Route::get('/', ['uses' => 'IndexController@home', 'as' => 'home']);
Route::post('/', ['uses' => 'IndexController@price', 'as' => 'price']);
Route::get('contact', ['uses' => 'ContactController@show', 'as' => 'contact']);
Route::post('contact', ['uses' => 'ContactController@send', 'as' => 'contact-send']);
Route::get('/category/{category}', ['uses' => 'CategoryController@show', 'as' => 'category']);
});
错误文本:缺少 [Route: category] [URI: {language}/category/{category}] 所需的参数。(查看:/Applications/MAMP/htdocs/shop/resources/views/index.blade.php)
我认为问题是我错误地插入了第二个参数,请帮助我,在此先感谢;)
解决方案
将参数作为数组传递。
route('category', ['language' => app()->getLocale(), 'category' => $category->name])
推荐阅读
- presto - 如何在 presto 中将 varbinary 转换为 varchar
- python - 扩展名为 .ipynb/.py 的 Python 程序在转换为 .exe 时不起作用?
- r - ShinyApp 函数不返回结果
- stripe-payments - 更改未付款 Stripe 订单上的商品
- ssas - SSAS表格项目连接问题-memSQL DB作为数据源
- reactjs - React Router:导航到 /compose/tweet 但保持正交的先前路由(如:/notifications)已安装
- angular - ngModel 使 datePicker 今天的日期返回 null
- jquery - Jquery ajax按钮不会提交
- jquery - 如何使用jquery按行检查表中的所有复选框?
- firebase - Flutter Firebase 通过 ID 数组获取文档