我打算使用 where 子句对 laravel 雄辩模型进行分页。我希望页面链接能够显示并可点击,从而指向被点击的页面。这是我在其中分页时没有 where 子句的默认控制器。 public function index(Request $request){ $users = User::paginate(12)->onEachSide(1); return view('/**',compact('users'));}我可以分页到最后一页。这是路线(为了保密,我把名字加了星号。:Route::get('/**', 'SearchController@index');这个功能更好,但是我尝试用 where 子句限制行: public function search(Request $request){$location = $request->location;$talent = $request ->talent;$users = User::where('talent',$talent)->where('location',$location)->paginate(12);return view('/searchResult',compact('users'); }这是路线:Route::get('/**', 'SearchController@search');但是,在第二种情况下,当我尝试导航时分页结果返回空白。我不确定为什么会这样。在正面视图中,我有: {{$users->links()}}
1 回答

Helenr
TA贡献1780条经验 获得超4个赞
这段代码有效,我现在可以有效地分页了。lufc 在评论中回答。但是,我对这个机制很好奇。
{{ $users->appends(Request::except('page'))->links() }}
- 1 回答
- 0 关注
- 141 浏览
添加回答
举报
0/150
提交
取消