Language

How to get last record from table using eloquent in Laravel 5.4

Date 13 Aug, 2017

Details :

1. You can get last record or row of table using two ways:

(a) using orderBy clause

    $row=DB::table('posts')->orderBy('id', 'desc')->first();

(b) using latest() function

    $row=DB::table('posts')->latest()->first();