Loading…

How to get last inserted id using laravel query?

In case you are using save()

$blog = new Blog;
$blog->title = ‘Best Interview Questions’;
$blog->save()

// Now you can use (after save() function we can use like this)

$blog->id // It will display last inserted id

In case you are using insertGetId()

$insertGetId = DB::table(‘blogs’)->insertGetId([‘title’ => ‘Best Interview Questions’]);

Suggest An Answer

No suggestions avaliable!

Latest post from Laravel Interview Questions

Ask Question