使用Laravel Eloquent获取所有最新记录 [英] Get All Latest Records Using Laravel Eloquent

查看:58
本文介绍了使用Laravel Eloquent获取所有最新记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试用这种方式查询数据库,但是它返回错误.

I tried querying the database this way but it returns the error.

找不到

latest().

latest() not found.

DailyReport::get()->latest()->paginate(10)

我希望它返回所有带有分页的DailyReports.

I want it to return all the DailyReports with pagination.

推荐答案

latest()方法是 orderBy('created_at','desc')的缩写.您可以通过以下方式实现所需的目标:

The latest() method is short for orderBy('created_at', 'desc'). You can achieve what you want by:

$latest_daily_reports = DailyReport::latest()->paginate(10);

您还可以更改列 latest()的顺序.

You can also change the column latest() orders by.

->latest('your_column_name');

这篇关于使用Laravel Eloquent获取所有最新记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆