Language

How To get last inserted id in table using eloquent in Laravel 5.4

Date 12 Aug, 2017

Details :

1. You can get last last inserted id into a table by using query $id= DB::getPdo()->lastInsertId();

User::create([
              'username' => $username,
              'firstname' => $data['fname'],
              'lastname' => $data['lname'],
              'password' =>bcrypt($data['password']),
              'email' => $data['email'],
              'user_type' =>  2,
              'status' =>1,
            ]);
            $id= DB::getPdo()->lastInsertId();