我正在使用 laravel 分页,但分页的 url 不是相对的,它会将新的 url 附加到以前的 url,例如,如果我当前的 url 是“ http://localhost:8080/event-home/1 ”,那么当我点击第二页时它生成链接为“ http://localhost:8080/event-home/1#http://localhost:8080/event-home/1?page=2 ”
如您所见,它附加到上一个 url,因此它不会返回下一页。实际上 URL 应该像“ http://localhost:8080/event-home/1?page=2 ” 以下是相同的代码
if (Session::get('event_id') != null){
$members = Event::find(Session::get('event_id'))->users()->orderBy('name','asc')->paginate(5);
if ($request->ajax()) {
if($request->page) {
return view('event.members', ['members' => $members]);
}
else
return view('event.event-home', ['members' => $members]);
}
这是我的视图代码:
@foreach($members as $member)
<div class="col-lg-3 col-md-4 col-xs-6 member" id="memberId_{{$member->id}}">
<div class="caption">
<a href="/profile/{{$member->id}}" class="d-block mb-4 h-100">
<img class="img-fluid img-thumbnail" src="{{url('images/users/'.$member->id.'/profile_image/'.$member->avatar_url)}}" alt="">
</a>
<center> <a href="/profile/{{$member->id}}"> {{$member->name }} {{$member->profiles->last_name}}</a></center>
</div>
</div>
@endforeach
{{ $members->links() }}
谢谢!