Laravel get last inserted Id


Laravel get last inserted Id : If you are working with laravel database tables and performing insert operation on them you can use the following method to get the last inserted id.


Syntax for Laravel get last inserted Id

Below is an insert query example in laravel.

DB::table('users')->insert(array("id"=>$uid,"name"=>$name,"email"=>$email));
$lastInsertedId = DB::connection('mysql')->pdo->lastInsertId();

Which will return the last inserted id in the laravel table.


Advertisements

Add Comment

📖 Read More