【问题标题】:How to user orderBy and Paginate at the same time in Laravel 5如何在 Laravel 5 中同时使用 orderBy 和 Paginate
【发布时间】:2016-09-05 23:52:41
【问题描述】:

我正在尝试对列表进行分页和排序,它给了我错误方法 orderby 不存在。下面是代码:

命名空间 App\Providers;

use Illuminate\Support\ServiceProvider;
use App\Edisi;
use DB;
use View;

class EdisiServiceProvider extends ServiceProvider {
    public function boot() {
        View::composer(['edisi/index', 'pages/home'], function ($view) {
            $edisi_list = DB::table('edisi')->paginate(3)->orderBy('id')->get();
            $view->with('edisi_list', $edisi_list);
        });
    }
    public function register() {
    }
}

【问题讨论】:

    标签: laravel laravel-5


    【解决方案1】:

    您需要在对结果进行分页之前调用orderBy()(您也不需要调用get())。

    所以你会:

    $edisi_list = DB::table('edisi')->orderBy('id')->paginate(3);
    

    【讨论】:

      猜你喜欢
      • 2016-01-21
      • 1970-01-01
      • 2022-08-04
      • 2018-07-06
      • 2016-08-27
      • 2018-03-29
      • 2019-04-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多