I built a laravel 5 application and now I am testing how it handles different inputs. Thus I encountered a weird problem. In the header I have a search field. It returns results, paginated by 10.
The problem
If a user inputs a letter, for an example "e" in English, everything works just fine. However, when a user enters a letter, for an example "e" in Bulgarian - the first page of the results is shown correctly and when a user hits page 2 the query in the search from "е" in Bulgarian changes to "%D0%B5" and no more results are shown. Here is an actual link to the website. http://podobri.eu
I guess this has something to do with the encoding but I can't see what I am doing wrong.
Here is the actual code
Route
Route::get('/search', [
'uses' => '\Podobri\Http\Controllers\SearchController@getResults',
'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".'" в системата на Подобри');
}
View
@foreach($problems as $problem)
<div>
@include('problems.partials.problemblock')
</div>
@endforeach
<!-- Paginating-->
{!! $problems->appends(Request::except('page'))->render() !!}
Search form
<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>