我想将翻译功能添加到我的网站。但我遇到了这个问题
缺少 [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>
似乎您从未在按钮元素上将
$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');
兹拉坦
“品牌”是一个过滤器
<a class="btn btn-default" href="{{ url(app()->getLocale().'/project/Branding') }}" role="button">Branding</a>