php Laravel 分页顺序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19885907/
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 paginate order by
提问by s0hno
What should I do to pass the values ??that you order by in patinate?
我应该怎么做才能传递您在 patinate 中订购的值?
routes.php
路由文件
$ondata = DB::table('official_news') -> orderBy('created_date', 'desc') -> get() -> paginate(7);
return View::make('main',array('ondata' => $ondata));
error
错误
Call to a member function paginate() on a non-object
I need your help
我需要你的帮助
回答by
This should do the trick:
这应该可以解决问题:
$ondata = DB::table('official_news')->orderBy('created_date', 'desc')->paginate(7);
$ondata = DB::table('official_news')->orderBy('created_date', 'desc')->paginate(7);
回答by Santee
It will be better if you order it by the id because it is going to be faster from the database.
如果按 id 排序会更好,因为从数据库中它会更快。
$posts = Post::orderBy('id', 'desc')->paginate(6);
https://laracasts.com/discuss/channels/laravel/combining-paginate-with-orderby
https://laracasts.com/discuss/channels/laravel/combining-paginate-with-orderby
It works fine for Laravel 5.1.
它适用于 Laravel 5.1。
回答by benjamintemitope
You can use something like this in your controller file.
您可以在控制器文件中使用类似的内容。
$transactions = Transaction::orderBy('name')->paginate(10);
return view('index', compact('transactions'));