我打算使用 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 關注
- 124 瀏覽
添加回答
舉報
0/150
提交
取消