Laravel Eloquent 关系:->latest() [英] Laravel Eloquent Relations: ->latest()
本文介绍了Laravel Eloquent 关系:->latest()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
laravel中latest()的作用是什么?
What is the function of latest() in laravel?
示例:
public function activity()
{
return $this->hasMany('AppActivity')
->with(['user', 'subject'])
->latest();
}
我一直在看 Laravel 文档,但我找不到它...
I've been looking in the laravel documentation, but I couldn't find it...
推荐答案
latest()
是一个定义在 IlluminateDatabaseQueryBuilder
类中的函数.它的工作非常简单.这是它的定义方式.
latest()
is a function defined in IlluminateDatabaseQueryBuilder
Class. It's job is very simple. This is how it is defined.
public function latest($column = 'created_at')
{
return $this->orderBy($column, 'desc');
}
因此,它只会 orderBy
与您以 descending
顺序提供的列一起使用,默认列将是 created_at
.
So, It will just orderBy
with the column you provide in descending
order with the default column will be created_at
.
这篇关于Laravel Eloquent 关系:->latest()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文