我在Laravel 5中实现分页时遇到了一些问题。虽然可能不是你想的那样。我可以让一切正常工作,但不明白如何在第二页上提取正确的信息。这是我所拥有的:
路线:
Route::resource('find-a-wp-theme', 'searchController');
控制器:
public function store(){
$themes['themes'] = Fulls::where("tags", "like", "%".$_POST['theme']."%")->orwhere("tags", "like", "%".$_POST['free']."%")->orwhere("title", "like", "%".$_POST['free']."%")->paginate(12);
return view('find-a-wp-theme', $themes);
}
视图:
@if($themes)
@foreach($themes as $theme)
{{$theme['title']}}<br />
<img style="width:250px;" src="{{$theme['image']}}"><br />
@endforeach
{!! $themes->render() !!}
@endif
到目前为止一切都很顺利。我的问题是,当我点击分页按钮时,它会把我带到我的页面?page=2,这实际上把我带到了资源index()
,我不明白如何正确地实现它。任何帮助都将不胜感激!
查看文档中的append。http://laravel.com/docs/5.0/pagination
如果您试图在URL中传递变量,则需要使用appends()。
<?php echo $users->appends(['sort' => 'votes'])->render(); ?>