【问题标题】:Laravel Pagination with get() functionLaravel 分页与 get() 函数
【发布时间】:2017-08-30 05:46:57
【问题描述】:

这是控制器功能。我需要为此设置分页。

public function student_list(){
        $students = Student::orderBy('first_name')->get();
        $stu_na = "Test Page";
        return view('student/student_list', compact('stu_na', 'students'));
}

阅读文档后,我尝试了以下方法。

第一种方式: $students = Student::orderBy('first_name')->get()->paginate(5);

错误:方法分页不存在。

第二种方式$students = Student::orderBy('first_name')->paginate(5)->get();

错误:类型错误:函数参数太少 Illuminate\Support\Collection::get()

我应该如何在我的控制器中使用分页?

【问题讨论】:

    标签: php laravel laravel-5 pagination laravel-pagination


    【解决方案1】:

    您不需要->get()->paginate() 将在内部自行执行查询。

    $students = Student::orderBy('first_name')->paginate(5);
    

    【讨论】:

      猜你喜欢
      • 2017-03-06
      • 2013-06-14
      • 2015-06-11
      • 1970-01-01
      • 1970-01-01
      • 2017-06-03
      • 1970-01-01
      • 2016-08-05
      • 2015-11-21
      相关资源
      最近更新 更多