Pagination 分页不';t与行动后的laravel 5一起工作
在Laravel 5中使用分页时,我遇到了一个问题。这种情况下,我希望对搜索结果进行分页,我的代码工作并显示与搜索匹配的内容,但当我希望看到其他结果(page=2)时,它不显示任何内容,并且我得到一个路由异常Pagination 分页不';t与行动后的laravel 5一起工作,pagination,laravel-5,Pagination,Laravel 5,在Laravel 5中使用分页时,我遇到了一个问题。这种情况下,我希望对搜索结果进行分页,我的代码工作并显示与搜索匹配的内容,但当我希望看到其他结果(page=2)时,它不显示任何内容,并且我得到一个路由异常 MethodNotAllowedHttpException in RouteCollection.php line 207: 分页是否仅适用于GET操作 我非常感谢你的帮助 这是到目前为止我的代码 SearchController.php /* Bring the form */ pub
MethodNotAllowedHttpException in RouteCollection.php line 207:
分页是否仅适用于GET操作
我非常感谢你的帮助
这是到目前为止我的代码
SearchController.php
/* Bring the form */
public function index()
{
$levels = Level::all();
return view('search.seek')->with('levels',$levels);
}
/**
* Display results that matches my search
* @param Request $request
* @return Response
*/
public function results(Request $request)
{
$suggestions = Suggestion::where('subject','=',$request->subject,'and')
->where('level','=',$request->level,'and')
->where('grade','=',$request->grade,'and')
->where('topic','=',$request->topic,'and')
->where('device','=',$request->device)->latest()->paginate(5);
$suggestions->setPath('results');
return view('search.list')->with('suggestions', $suggestions);
}
Route.php
Route::post('results',[
'as' => 'results_path',
'uses' => 'SearchController@results' ]);
list.blade.php
@if($suggestions != null)
<h1 class="page-heading">Resultados</h1>
@foreach($suggestions->chunk(5) as $Suggestions)
<div class="row">
<div class="col-lg-12">
@foreach($Suggestions as $suggestion)
<div id="postlist">
<div class="panel">
<div class="panel-heading">
<div class="text-center">
<div class="row">
<div class="col-sm-9">
<h3 class="pull-left">{!! \App\Topic::find($suggestion->topic)->name !!}</h3>
</div>
<div class="col-sm-3">
<h4 class="pull-right">
<small><em>{!! $suggestion->created_at->format('Y-m-d') !!}</em></small>
</h4>
</div>
</div>
</div>
</div>
<div class="panel-body">{!! $suggestion->how_to_use !!}</div>
<div class="panel-footer"><span class="label label-default">Por: {!! \App\User::find($suggestion->user_id)->name !!}</span><span class="label label-success pull-right">{!! link_to('results/' .$suggestion->id ,'Ver',null) !!}</span></div>
</div>
</div>
@endforeach
</div>
</div>
@endforeach
{!! $suggestions->render() !!}
@endif
@if($suggestions!=null)
Resultados
@foreach($suggestions->chunk(5)作为$suggestions)
@foreach($建议作为$建议)
{!!\App\Topic::find($suggestion->Topic)->name!!}
{!!$suggestion->created_at->format('Y-m-d')
{!!$建议->如何使用!!}
Por:{!!\App\User::find($suggestion->User\u id)->name!!}{!!link\u to('results/。$suggestion->id,'Ver',null)
@endforeach
@endforeach
{!!$suggestions->render()!!}
@恩迪夫
是分页仅适用于get参数
您应该为搜索页面使用GET
方法<代码>发布请求并不用于显示数据。为什么?原因有很多,但简而言之,我将举两个例子:
GET
参数,假设您位于第六页-您可以复制链接并将其粘贴到朋友,他将能够查看与您相同的内容。使用POST
这是不可能的POST
请求使用“后退”按钮POST
请求在您需要向服务器提交数据以创建新记录时非常有用
因此,我建议您将路线类型更改为
GET
,将搜索表单方法更改为GET
确实,您可以将表单与POST方法结合使用。分页链接是GET请求,但这是自动的,您可以使用多种方法放置路由定义,并且功能将是自动的
对于route.php来说,类似这样的东西应该可以工作
Route::match(['get', 'post'], 'results',[
'as' => 'results_path',
'uses' => 'SearchController@results' ]);
使用它的gonaa在post中工作谢谢伙计,你的解释对我很有用,我已经将它更改为获取resquest,它工作了,但它只检索前5条记录,我仍然看不到其他记录,使用分页按钮时它什么也不显示,我会继续查的你也说服我改为搜索而不是发帖,thanks@AngelSalazar,使用分页按钮时是否维护查询字符串?为分页链接尝试$suggestions->appends(请求::除('page'))->links()。GET请求参数也有问题。其中最大的问题是,作为查询字符串传递的数字被转换为字符串。当在POST request body.Ty中传递参数以获取答案(文档中未提及的内容)时,不会发生这种情况。第二个参数指的是什么?请提供有关此方法的足够信息,并解释参数。此方法信息:这是传奇,为我工作:DNice one。即使在拉威尔6也能工作。您还必须注意在视图$data->appends(Request::all())->links()中添加以下内容
DB::table($table)->paginate($perPage,['*'],'page',$page);