saving user field type custom field - Failed to set unsafe attribute
In order to set field values there is setFieldValue function

$element-&gt;setFieldValue('fieldHandle', [Craft::$app-&gt;getUser()-&gt;getIdentity()-&gt;id]);


All relation fields only accept the values as an array [1] rather than integer 1