如何在laravel中使用分页

问题描述 投票:0回答:1

我有一张桌子

news

在我的控制器中,我写道:

public function datnuoc(){

    $tinxkldMoi1 = DB::table ( 'news' )->where ( 'datnuoc',1)->where('status',1)->orderBy('endDate', 'desc')->orderBy('created_at', 'desc')->paginate(20);  
    $tinxkldMoi2 = DB::table ( 'news' )->where ( 'datnuoc',1)->take(5)->orderBy('endDate', 'desc')->orderBy('created_at', 'desc')->paginate(20);
    $tinxkldMoi3 = DB::table ( 'news' )->where ( 'datnuoc',1)->where('status',3)->take(5)->orderBy('endDate', 'desc')->orderBy('created_at', 'desc')->paginate(20);

    return View::make ( 'home/current',array(
            'tinxkldMois1'=> $tinxkldMoi1,
            'tinxkldMois2'=> $tinxkldMoi2,
            'tinxkldMois3'=> $tinxkldMoi3,

    ));
}

在主页/当前视图中,我写了:

<php>
{{$tinxkldMois1->links()}}
{{$tinxkldMois2->links()}}
{{$tinxkldMois3->links()}}
</php>

为什么我点击其中一个部分可以工作,但其他部分却不起作用?

laravel pagination
1个回答
0
投票

您不能在同一查询中使用

take()
paginate()
,两者都设置
limit
,因此
take()
将被忽略。对于最后两个查询,将
paginate(20)
替换为
take(5)->get()

© www.soinside.com 2019 - 2024. All rights reserved.