Get user ID for database insert I have a form inserting into a database in Drupal 8. I would like to insert the user id. I have the following code:

$userCurrent = \Drupal::currentUser();
$uname = (int)User::load($userCurrent-&gt;id());


Without the (int) Drupal throws an error saying it cannot be converted into a string. With the (int) Drupal always returns 1. What am I doing wrong?

UPDATE: As stated I would like the user ID not the user name. Sorry if it doesn't make sense, I am very new to Drupal and there is not a lot of documentation for 8 yet.
Do you want to get the username, as the variable name suggests?

$uname = User::load($userCurrent-&gt;id())-&gt;name-&gt;value;


Your question does not make sense, why load the user with the id to get the id, you already have?