Get last inserted id in Laravel 5

In Laravel after saving records with Laravel Eloquent you can get last inserted id by getting id property of the same obj from which you have saved.

Example

public function saveUser(){
  $user =new User();
  $user->name="Ravi";
  $user->address="New Delhi";
  $user->save();
//Getting last inserted id
  return $user->id;
}

Leave a Reply

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