我建立了一个 Laravel 5 应用程序,现在正在测试它如何处理不同的输入。因此,我遇到了一个奇怪的问题。在标题中,我有一个搜索字段,返回每页10个结果。如果用户输入英文字母,例如“e”,一切正常。然而,当用户输入保加利亚语字母“е”时,第一页结果正确显示,但当用户点击第二页时,搜索框中的查询从保加利亚语字母“е”变为“%D0%B5”,不再显示结果。这是网站的实际链接:http://podobri.eu。
我猜测这与编码有关,但我看不出我的错误在哪里。
以下是实际代码:
路由
搜索表单
我猜测这与编码有关,但我看不出我的错误在哪里。
以下是实际代码:
路由
Route::get('/search', [
'uses' => '\Podobri\Http\Controllers\SearchController@getResults',
'as'=>'search.results',
]);
搜索控制器
public function getResults(Request $request){
$query = $request->input('query');
$comments = Comment::where(function($query){
return $query;
})->orderBy('created_at', 'desc')->get();
if(!$query || $query==''){
return view('problems.index')->with('comments', $comments);
}
$problems = Problem::where(DB::raw("CONCAT(problem_title, ' ', problem_description)"), 'LIKE', "%$query%")
->orWhere('location', 'LIKE', "%$query%")
->orWhere('category', 'LIKE', "%$query%")
->orderBy('created_at', 'desc')->paginate(10);
Carbon::setLocale('bg');
return view('search.results')
->with('comments', $comments)
->with('problems', $problems)
->with('title', 'Резултати за "'."$query".'" | Подобри')
->with('description', 'Резултати за "'."$query".'" в системата на Подобри');
}
查看
@foreach($problems as $problem)
<div>
@include('problems.partials.problemblock')
</div>
@endforeach
<!-- Paginating-->
{!! $problems->appends(Request::except('page'))->render() !!}
搜索表单
<form action="{{ route('search.results') }}" role="search" class="navbar-form navbar-left head-form-responsive">
<div class="form-group">
<input type="text" required id='searchQuery' title="Търсете за проблеми" value="{{ Request::input('query') }}" name="query" class="form-control"
placeholder="Търсете за проблеми"/>
</div>
<button type="submit" id='searchBtn' class="btn btn-default">Търсете</button>
</form>
$query = $request->input('query');
更改为$query = urldecode($request->input('query'));
吗? - phaberest&page=X
。 - phaberest