Laravel雄辩的关系:-> latest() [英] Laravel Eloquent Relations: ->latest()

查看:1774
本文介绍了Laravel雄辩的关系:-> latest()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

laravel中latest()的功能是什么?

What is the function of latest() in laravel?

示例:

public function activity()
{
    return $this->hasMany('App\Activity')
        ->with(['user', 'subject'])
        ->latest();
}

来自构建活动在第44行输入Laravel .

我一直在寻找laravel文档,但找不到它...

I've been looking in the laravel documentation, but I couldn't find it...

推荐答案

latest()是在Illuminate\Database\Query\Builder类中定义的函数.它的工作非常简单.这是它的定义方式.

latest() is a function defined in Illuminate\Database\Query\Builder Class. It's job is very simple. This is how it is defined.

public function latest($column = 'created_at')
{
    return $this->orderBy($column, 'desc');
} 

因此,它将与您按descending顺序提供的列一起为orderBy,默认列为created_at.

So, It will just orderBy with the column you provide in descending order with the default column will be created_at.

这篇关于Laravel雄辩的关系:-> latest()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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