首页 > 解决方案 > 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)

我认为问题是我错误地插入了第二个参数,请帮助我,在此先感谢;)

标签: phplaravel

解决方案


将参数作为数组传递。

route('category', ['language' => app()->getLocale(), 'category' => $category->name])

推荐阅读