猿问

为什么 Laravel 5.7 分页在第一页结果后不显示更多页面

我打算使用 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()}}


慕娘9325324
浏览 142回答 1
1回答

Helenr

这段代码有效,我现在可以有效地分页了。lufc 在评论中回答。但是,我对这个机制很好奇。     {{ $users->appends(Request::except('page'))->links() }}
随时随地看视频慕课网APP
我要回答