我目前正在编写我的laravel项目,我有一个 我的观点有两个不同的分页问题。在第一个分页中, 当我尝试点击(2 - 这是下一页)时,第二个分页受到影响 即使它在行渲染中有不同的变量。任何人都知道它为什么 发生?
我的控制器
public function viewlist($ship_id){
$members = Member::where('ship_id','=',$ship_id)->paginate(3);
$member = Member::where('ship_id','=',$ship_id)->get();
$member_ids = [];
foreach ($member as $mem) {
array_push($member_ids, $mem->scholar_id);
}
$pendings = AddRequest::where('ship_id','=',$ship_id)->paginate(3);
$pending = AddRequest::where('ship_id','=',$ship_id)->get();
$pending_ids = [];
foreach ($pending as $pend) {
array_push($pending_ids, $pend->scholar_id);
}
$recommends = Recommend::where('ship_id', '=',$ship_id)->get();
return view('pages.Organization.List-Of-Organization-Scholar',compact('ship','schol','pendings','members','count_member','recommends'))
;}
我的观点
@foreach($members as $member)
<div class="col-lg-4">
<div class="col-lg-12 well">
<a class="thumbnail" href="#">
<img class="img-responsive" src="../{!! $member->Memscholar->scholar_image !!}" alt="" height="150" width="200">
</a>
</div>
</div>
@endforeach
<div class = "col-md-12">
{!! $members->render() !!}
</div>
@foreach($pendings as $pending)
<div class="col-lg-4">
<div class="col-lg-12 well">
<a class="thumbnail" href="#">
<img class="img-responsive" src="../../{!! $pending->Pendscholar->scholar_image !!}" alt="" height="150" width="200">
</a>
</div>
</div>
@endforeach
<div class = "col-md-12">
{!! $pendings->render() !!}
</div>
答案 0 :(得分:0)
//控制器
//在创建分页器之前更改页面名称:
Paginator::setPageName('page_a');
$collection_A = ModelA::paginate(10);
Paginator::setPageName('page_b');
$collection_B = ModelB::paginate(10);
//查看
//执行相同操作:在打印链接之前更改页面名称
Paginator::setPageName('page_a');
$collection_A->links();
Paginator::setPageName('page_b');
$collection_B->links();
//如果您在导航到其他页面时不想丢失任何页面状态,请将所有集合中的当前页面附加到链接:
Paginator::setPageName('page_a');
$collection_A->appends('page_b', Input::get('page_b',1))->links();
Paginator::setPageName('page_b');
$collection_B->appends('page_a', Input::get('page_a',1))->links();
来源:
http://laravel-tricks.com/tricks/multiple-pagination-with-laravel-2-pagination-in-1-page