Get last id in laravel
$last3 = DB::table('items')->latest('id')->first();
Get last id in laravel
$last3 = DB::table('items')->latest('id')->first();
get the last inserted Id using laravel eloquent
//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();
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us