我想将翻译功能添加到我的网站。但我遇到了这个问题
Missing required parameters for [Route: filterdata] [URI: {locale}/project/{filter}]
这是应用程序的网络路线:
Route::get('/', function () {
return redirect(app()->getLocale());
});
Route::get('/project', function () {
return redirect(app()->getLocale());
});
Route::group([
'prefix' => '{locale}',
'where' => ['locale' => '[a-zA-Z]{2}'],
'middleware' => 'setlocale',
], function(){
Route::get('/', function(){
return view('pages.home');
})->name('home');
Route::get('/project/{filter}', 'ProjectController@filterProject')->name('filterdata');
});
这是刀片项目
<a class="btn btn-default" href="{{ url(app()->getLocale().'/project/Branding') }}" role="button">Branding</a>
这是控制器:
public function filterProject($locale, $filter){
$locale = $locale;
$filter = str_replace('-',' ',$filter);
$url = Lang::get('proyek.project');
$url2 = json_encode($url);
$data = json_decode($url2, true);
$data = array_filter($data);
if(collect($data)->where('tag1',"{$filter}")->all() == true){
$project = collect($data)->where('tag1',"{$filter}")->all();
}elseif(collect($data)->where('tag2',"{$filter}")->all() == true){
$project = collect($data)->where('tag2',"{$filter}")->all();
}elseif(collect($data)->where('tag3',"{$filter}")->all() == true){
$project = collect($data)->where('tag3',"{$filter}")->all();
}else{
$project = collect($data)->all();
}
return view ('pages/projects', compact('project','locale','filter'));
}
这是我用于语言切换的按钮:
<div class="form-check d-flex align-items-center">
<input type="radio" class="form-check-input form-control" name="language" id="languageen" value="{{ route(\Illuminate\Support\Facades\Route::currentRouteName(), 'en') }}" onchange="location = this.value;" @if(app()->getLocale() == 'en') checked @endif>
<label class="form-check-label control-label" for="languageen">
EN
</label>
</div>
<div class="form-check d-flex align-items-center">
<input type="radio" class="form-check-input form-control" name="language" id="languageid" value="{{ route(\Illuminate\Support\Facades\Route::currentRouteName(), 'id') }}" onchange="location = this.value;" @if(app()->getLocale() == 'id') checked @endif>
<label class="form-check-label control-label" for="languageid">
ID
</label>
</div>
答案 0 :(得分:0)
似乎您从未在按钮元素上将$filter
变量传递给路线:
<a class="btn btn-default" href="{{ url(app()->getLocale().'/project/Branding') }}" role="button">Branding</a>
如您所见,您仅传递了$locale
参数。为了使其正常工作,您还传递了$filter
变量
<a class="btn btn-default" href="{{ url(app()->getLocale().'/project/Branding/' . $filter) }}" role="button">Branding</a>
如果每次调用此路由时都不需要$filter
,则可以使用?
运算符将其设置为可选:
Route::get('/project/{filter?}', 'ProjectController@filterProject')->name('filterdata');
答案 1 :(得分:0)
zlatan
“品牌”是过滤器
<a class="btn btn-default" href="{{ url(app()->getLocale().'/project/Branding') }}" role="button">Branding</a>