Laravel 5 Page URL Encoding Problem

I created a laravel 5 application, and now I am testing how it handles different inputs. So I ran into some kind of weird problem. In the title, I have a search box. It returns results broken down by 10.

Problem

If the user enters a letter, for example "e" in English, everything works fine. However, when the user enters a letter, for example, ā€œeā€ in Bulgarian - the first page of results is displayed correctly, and when the user types page 2, the search query from ā€œeā€ in Bulgarian changes to ā€œ% D0ā€% B5 ā€, and more results are not visible. Here is the actual link to the site.http: //podobri.eu

I guess this has something to do with the encoding, but I don't see what I'm 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> 
+3
source share
1 answer

It seems to me that your problem is happening because paginator adds a trailing slash with some odd redirection (not sure if you guys are using custom htaccess). For example, if you are looking for e, this is the URL:

 http://podobri.eu/search?query=e 

However, the URL of the second page is as follows:

 http://podobri.eu/search/?query=e&page=2 

Pay attention to the slash before ?query . If you remove the slash, this will work. So how can you fix this?

This was recorded several months ago. You can see this commit here: https://github.com/laravel/framework/commit/806fb79f6e06f794349aab5296904bc2ebe53963

So, if you are using L5.1 or 5.2, you can run composer update and it will fix itself. However, if you are using 5.0, it seems that it still has this error, so you can use the setPath method and try instead:

 {!! $problems->setPath('')->appends(Request::except('page'))->render() !!} 
+4
source

All Articles