As the title says, I am trying to get the values from a custom field I added to the user profile. I am using this code from a previously asked question regarding this.
$user = \Drupal\user\Entity\User::load(\Drupal::currentUser()->id());
$value = user->custom_field->value;
This seemed to work for the person that previously asked this question but the problem I am running into is that it is only returning values of an anonymous user regardless of who I am logged in as. For example if I replace custom_field with uid it will return a value of '0'. Any idea where I could be going wrong?