How to Get Laravel last inserted ID from database

Today, We want to share with you How to Get Laravel last inserted ID from database.
In this post we will show you Fetching the last insert ID with Laravel, hear for How to get last insert id in Eloquent ORM laravel we will give you demo and example for implement.
In this post, we will learn about get last inserted id in laravel PHP Framework with an example.

Get Laravel last inserted ID PHP Framework

In core PHP, We can simple use PHP function mysqli_insert_id to fetch last inserted record id. but here Laravel used To Get Codeigniter last inserted ID function such as a insertGetId()

public function getLastInsertedId()
	$id = DB::table('users')->insertGetId(
			['email' => '[email protected]', 'name' => 'jaydeep Gondaliya']

php – Get last insert id using Laravel

Laravel Get Last Inserted Id

    public function getLastInsertedId()
        $user = User::create(['name'=>'jaydeep Gondaliya','email'=>'[email protected]']);

Laravel Global variables

mysqli_insert_id() simple PHP function will here return zero if database table does not have exists autoincremented created column so create first sure database table must have a new column with primary key set such as a AUTO_INCREMENT Set attribute.

Read :


You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about PHP laravel 5.6 get last insert id.
I would like to have feedback on my blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, donโ€™t forget to share.