You can use latest():
DB::table('tbl')->latest()->first();
or
DB::table('items')->latest('date')->first();
Under the hood:
latest()will be orderBywith the column that you specify in the descendingorder where the default column will be created_at.
public function latest($column = 'created_at')
{
return $this->orderBy($column, 'desc');
}
source
share