Php Laravel 5路由分页url编码问题

Php Laravel 5路由分页url编码问题,php,laravel,encoding,pagination,laravel-5,Php,Laravel,Encoding,Pagination,Laravel 5,我构建了一个Laravel5应用程序,现在我正在测试它如何处理不同的输入。因此,我遇到了一个奇怪的问题。在标题中,我有一个搜索字段。它返回结果,分页为10 问题 如果用户输入一个字母,例如英语中的“e”,一切正常。但是,当用户输入字母时,例如保加利亚语中的“e”-结果的第一页显示正确,当用户点击第2页时,搜索中的查询从保加利亚语中的“e”更改为“%D0%B5”,不再显示更多结果。这是该网站的实际链接 我想这与编码有关,但我看不出我做错了什么 这是实际代码 路线 搜索控制器 public func

我构建了一个Laravel5应用程序,现在我正在测试它如何处理不同的输入。因此,我遇到了一个奇怪的问题。在标题中,我有一个搜索字段。它返回结果,分页为10

问题

如果用户输入一个字母,例如英语中的“e”,一切正常。但是,当用户输入字母时,例如保加利亚语中的“e”-结果的第一页显示正确,当用户点击第2页时,搜索中的查询从保加利亚语中的“e”更改为“%D0%B5”,不再显示更多结果。这是该网站的实际链接

我想这与编码有关,但我看不出我做错了什么

这是实际代码

路线

搜索控制器

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作为$problem)
@包括('problems.partials.problemblock')
@endforeach
{!!$problems->appends(请求::除('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>

Търсете

在我看来,您的问题似乎发生了,因为paginator在尾部添加了一个斜杠,带有一些奇怪的重定向(不确定您是否正在使用自定义htaccess)。例如,如果您搜索e,这是URL:

http://podobri.eu/search?query=e
但是,第二页的URL如下所示:

http://podobri.eu/search/?query=e&page=2
请注意
?query
前面的斜杠。如果删除斜杠,它会起作用。那么,你如何解决这个问题呢

这实际上是几个月前修复的。您可以在此处看到此提交:

因此,如果您使用的是L5.1或5.2,您可以运行
composer update
,它会自行修复。但是,如果您使用的是5.0,它似乎仍然存在此错误,因此您可以使用
setPath
方法并尝试以下操作:

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

我有一个类似的问题,我的解决方案改变了路线的方法

Route::post('uri', 'Controller@function')
    ->name ('view.function');
用于:

这对我很有用


问候您,祝您好运。

当您点击第2页时,此操作方法与处理数据的方法相同?我不清楚您的意思。我做了一些被认为是不好的事情吗?不,我的意思是这个方法getResults()与转到第2页时使用的方法相同?您是否尝试过更改
$query=$request->input('query')
$query=urldecode($request->input('query')?我可以替他回答,是的,是一样的。Laravel在URL末尾添加
&page=X
对其进行分页我正在使用Laravel 5.0。尝试你的解决方案。工作得很有魅力。非常感谢。
{!! $problems->setPath('')->appends(Request::except('page'))->render() !!}
Route::post('uri', 'Controller@function')
    ->name ('view.function');
Route::any('uri', 'Controller@function')
    ->name ('view.function');