Laravel 5 个页面上的多个分页
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29058619/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel 5 multiple paginations on one page
提问by leoel
I'm trying to have 2 paginations on a single page.
我试图在一个页面上有 2 个分页。
View:
看法:
{{!! $items->appends(['page2' => Request::input('page2', 1)])->render() !!}}
But it is not working, as using custom $pageName for pagination ($items->setPageName('custom_page_parameter')) links are not working in laravel 5.
但它不起作用,因为使用自定义 $pageName 进行分页 ($items->setPageName('custom_page_parameter')) 链接在 laravel 5 中不起作用。
Here is how I did it in laravel 4:
这是我在 Laravel 4 中的做法:
Laravel Multiple Pagination in one page
What is Laravel 5 way of doing this?
Laravel 5 这样做的方法是什么?
回答by Timothy Victor
I've spent far too much time trying to find out how to do this, so thought I'd share my findings in case there is another poor soul like me out there. This works in 5.1...
我花了太多时间试图找出如何做到这一点,所以我想我会分享我的发现,以防万一有另一个像我这样的可怜人。这适用于 5.1 ...
In controller:
在控制器中:
$newEvents = Events::where('event_date', '>=', Carbon::now()->startOfDay())
->orderBy('event_date')
->paginate(15,['*'], 'newEvents');
$oldEvents = Events::where('event_date', '<', Carbon::now()->startOfDay())
->orderBy('event_date', 'desc')
->paginate(15,['*'], 'oldEvents');
Then continue as usual in the view: `
然后在视图中照常继续:`
// some code to display $newEvents
{!! $newEvents->render() !!}
// some code to display $oldEvents
{!! $oldEvents->render() !!}
Now, what this doesn't do is remember the page of $oldEvents when paging through $newEvents. Any idea on this?
现在,这不会做的是在对 $newEvents 进行分页时记住 $oldEvents 的页面。对此有什么想法吗?
References:
参考:
回答by anonym
$published = Article::paginate(10, ['*'], 'pubArticles');
$unpublished = Article::paginate(10, ['*'], 'unpubArticles');
The third argument for paginate() method is used in the URI as follows:
paginate() 方法的第三个参数在 URI 中使用,如下所示:
laravel/public/articles?pubArticles=3
laravel/public/articles?unpubArticles=1
laravel/public/articles?pubArticles=3
laravel/public/articles?unpubArticles=1
回答by mosleim
In Controller:
在控制器中:
$produk = Produk::paginate(5, ['*'], 'produk');
$region = Region::paginate(5, ['*'], 'region');
in view:
鉴于:
{{$produk->appends(['region' => $region->currentPage()])->links()}}
{{$region->appends(['produk' => $produk->currentPage()])->links()}}
reference to :[Laravel 5] Multi Paginate in Single Page
回答by leoel
Try using the \Paginator::setPageName('foo');
function befor buidling your paginator object:
尝试在构建\Paginator::setPageName('foo');
分页器对象之前使用该函数:
\Paginator::setPageName('foo');
$models = Model::paginate(1);
return view('view_foo', compact('models'));
This question might help too: Laravel 5 pagination, won't move through pages with custom page name
这个问题也可能有帮助:Laravel 5 pagination, won't move through pages with custom page name
Also note there is a bug atm: https://github.com/laravel/framework/issues/8000
另请注意有一个错误 atm:https: //github.com/laravel/framework/issues/8000