我构建了一个 Laravel 5 应用程序,现在正在测试它如何处理不同的输入。因此我遇到了一个奇怪的问题。在标题中我有一个搜索字段。它返回结果,按 10 分页。
问题
如果用户输入一个字母,例如英语中的“e”,一切都会正常。但是,当用户输入字母时,例如保加利亚语中的“e”,结果的第一页会正确显示,而当用户点击第 2 页时,搜索中的查询从保加利亚语中的“е”更改为“%D0” %B5”并且不再显示结果。这是该网站的实际链接。http://podobri.eu
我想这与编码有关,但我看不出我做错了什么。
这是实际的代码
Route
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".'" в системата на Подобри');
}
View
@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>