How to get last inserted id from table in Laravel

In this tutorial, we will explain to you about how to get last inserted id from the table in laravel. Sometimes when we need first table reference ID to insert to another table at that time we have to need last inserted ID of the first table.

If you want to get last inserted ID from the table. laravel provides the Eloquent library method such as save(), create(), insertGetId() and getPdo().

Using The save() Method

Using The create() Method

Using The insertGetId() Method

Using The getPdo() Method

Leave a Reply

Your email address will not be published. Required fields are marked *