Use insertGetId
to insert and get inserted id
at the same time
From doc
If the table has an auto-incrementing id, use the insertGetId method to insert a record and then retrieve the ID:
By Model
$id = Model::insertGetId(["name"=>"Niklesh","email"=>"[email protected]"]);
By DB
$id = DB::table('users')->insertGetId(["name"=>"Niklesh","email"=>"[email protected]"]);
For more details : https://laravel.com/docs/5.5/queries#inserts