Laravel latest() and oldest() Eloquent
The latest and oldest methods allow you to easily order results by table column. By default, result will be ordered by the
created_at 
column. You will pass the column name that you wish to sort by using
orderBy 
method. new method latest() eloquent
public function getLatestRecord()
{
    $latests = User::latest()->get();
}
old method OrderBy with latest eloquent
public function getLatestRecord()
{
    $latests = \DB::table('users')->orderBy('created_at','desc')->get();
}
new method oldest() eloquent
public function getOldestRecord()
{
    $oldest = User::oldest()->get();
}
by გიორგი ბაკაშვილი
4 years ago
Laravel
2
Pro tip: use ```triple backticks around text``` to write in code fences