$last3 = DB::table('items')->latest('id')->first();
//if you have used save method like this
$data->save();
//use this to get last row id;
$lastRowId = $data->id;
//For other insert methods get last inserted id like below
//Using create() method
$book = Book::create(['name'=>'Laravel Warrior']);
$lastId = $book->id;
//Using insertGetId()
$id = DB::table('books')->insertGetId( ['name' => 'Laravel warrior'] );
$lastId = $id;
//Using lastInsertId() method
$lastId = DB::getPdo()->lastInsertId();
$last = DB::table('items')->latest()->first();
DB::getPdo()->lastInsertId();
$id = DB::table('users')->insertGetId([
'email' => 'john@example.com',
'votes' => 0
]);
$last2 = DB::table('items')->orderBy('id', 'DESC')->first();
DB::table('myTable')->orderBy('id','desc')->first();
$data->save();
$data->id;