How to give each user a new attribute?

Hi,

I am working on a registration form and want to give each user a new attribute ‘personalid’ that stores something, so the users can be associated with their specific id.

I tried

$user = $kirby->users()->create([
    'email'     => esc(get('email')),
    'password'  => esc(get('password')),
    'language'  => esc(get('language')),
    'name'      => esc(get('name')),
    'personalid'   => $personalKey->id(),
    'role' => 'member'
]);

and expected that

echo $kirby->user()->personalid()

would return the value stored in that attribute. But it doesn’t. Do I need to add this attribute to the kirby user class? And if so, how do I do that?

Thanks!

Adding additional data does not work with the create method, you have to use $user->update() once the user is created.

1 Like