Get Last Register User's ID
You don't need to query the DB directly, you can use an entity query:

$uids = \Drupal::entityQuery('user')
  -&gt;sort('created', 'DESC')
  -&gt;range(0, 1)
  -&gt;execute();
$uid = reset($uids);