frezno
267
3
Nova

Computed default value for Text field

Posted 7 months ago by frezno

So what i'm trying is to add a text field with a computed value, ie one of the fields of the table contains a token. This token should be generated and then stored to the db when the new dataset is created and must not be overridden when other fields get updated (like to the nullable update on passwords).

The token is generated by using str_random() but whatever i tried so far, i can't make it to get the token string stored into the db.

Text::make('token')
    ->onlyOnDetail()
    ->updateRules('nullable')

    // and then something like that would be nice:
    ->defaultValue('token' function () {
            return str_random();
        })

Since i'm still pretty new toNova, maybe something like that exists, just i couldn't find it? Any help/idea is appreciated

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.