How to get the uid of a newly created user? I've been searching for this for ages, but could not come with a solution. Drupal 7 provided a way to get the uid of a newly created user after running user_save; the new user has been added and the uid has been returned in the object. However, now in Drupal 8 when I use the User::create() method, it only returns a constant based on whether the user has been created or updated. Is there any way to get the uid after the user has been created though? I don't seem to find a way. Any help is appreciated.
Where are you creating the user? Could you use entityTypeManager and EntityStorage instead of User::create()? I have the following in a method in a custom entity:

$storage = $this-&gt;entityTypeManager()-&gt;getStorage('user');
$owner =  $storage-&gt;create(['mail' =&gt; $email, 'name' =&gt; $this-&gt;getName()]);
$owner-&gt;save();
$uid = $owner-&gt;id();


If you don't have access to entityTypeManager() in your class, you could alternatively use:

$storage = \Drupal::service('entity_type.manager')-&gt;getStorage('user');