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->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.