我構建了一個laravel 5應用程序,現在我正在測試它如何處理不同的輸入。因此我遇到了一個奇怪的問題。在標題中我有一個搜索字段。如果用戶輸入一個字母,在英語的例子「E」,它返回的結果,由10Laravel 5路由分頁url編碼問題
問題
分頁,一切都運行得很好。但是,當用戶輸入一個字母時,例如保加利亞語中的「e」 - 結果的第一頁顯示正確,當用戶點擊第2頁時,保加利亞語中從「е」開始的查詢變爲「%D0 %B5「並且沒有顯示更多結果。這是一個到網站的實際鏈接。 http://podobri.eu
我想這與編碼有關,但我看不出我做錯了什麼。
下面是實際的代碼
路線
Route::get('/search', [
'uses' => '\Podobri\Http\Controllers\[email protected]',
'as'=>'search.results',
]);
SearchController
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>
當你打第2頁這個動作方法是相同的,其處理數據? –
我不清楚你的意思。我做了一些認爲不好的習慣嗎? –
不,我的意思是這個方法getResults()和page2一樣嗎? –