Laravel Rloquent Relations: & # 8594; last ()

What is the latest () function in laravel?

Example:

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

From Build Activity Channel in Laravel on line 44.

I searched the Laravel documentation, but I could not find this ...

+13
source share
3 answers

latest()is a function defined in a class Illuminate\Database\Query\Builder. It is very simple. Here is how it is defined.

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

So, it will be just orderBywith the column that you specify in descendingorder, the default column will be created_at.

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

→ latest() . , , "create_at" .

0
source

All Articles