Laravel Eloquent Relations: ->latest()

前端 未结 3 355
轻奢々
轻奢々 2020-12-15 16:23

What is the function of latest() in laravel?

Example:

public function activity()
{
    return $this->hasMany(\'App\\Activity\')
        ->with(         


        
3条回答
  •  佛祖请我去吃肉
    2020-12-15 17:01

    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');
    } 
    

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

提交回复
热议问题