简体   繁体   English

在 Laravel 上分页

[英]Paginate on Laravel

When I add a recording I would like to display the recordings oldest in my paginate.当我添加录音时,我想在我的分页中显示最旧的录音。 I should change the function "latest" ??我应该更改“最新”功能?

public function index(){
      $students = Student::latest()->paginate(5);
      return view('student.index', compact('students'))
             ->with('i', (request()->input('page',1)-1)*5);
    }

to get the results showing the oldest first use the oldest() function:要获得显示最旧的结果,首先使用最旧的() 函数:

public function index(){
      $students = Student::oldest()->paginate(5);
      return view('student.index', compact('students'))
             ->with('i', (request()->input('page',1)-1)*5);
    }

I recommend you to have a look to the Laravel Documentation: https://laravel.com/docs/5.7/queries我建议您查看 Laravel 文档: https ://laravel.com/docs/5.7/queries

Hope this could help you.希望这可以帮助你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM