1

Is there an option to generate Model-Values by not having a form input at the nova backend?

For example after every store / update I would like to update the created_by value with the current authenticated user.

Exampl:e

$model->created_by = aut()->user()->id

1 Answer 1

6

In your model, you can add a boot() method which will allow you to manage saving event

Available events are creating, created, updating, updated, saving, saved, deleting, deleted, restoring, restored

public static function boot()
{
    parent::boot();

    self::saving(function($model){
        $model->created_by = auth()->user()->id;
    });
}

In that way every time you create/update model created_by attribute will be updated..

Sign up to request clarification or add additional context in comments.

1 Comment

Perfect, i thought there is an way in nova but this seems pretty clear.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.