Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

IgorHrcek's avatar

Action in Nova does not update original and changes fields

I have a resource called Ip Address and an action for checking the PTR records. The PTR value is stored in the database after the action is performed.

On IpAddress model I've added the Actionable trait to have a nice log of actions performed.

Here is how action looks like:

    public function handle(ActionFields $fields, Collection $models)
    {
        foreach ($models as $model) {
            $model->ptr = Ptr::check($model->address);
            $model->save();
        }

        return Action::message('It worked!');
    }

The action works and the log of each execution exists, however the fields original and changes are not populated at all even though with each action execution the value of ptr is changed.

I do not have any fields defined in this action, nor I need them because the value is supposed to be generated from a DNS query.

So the question is - why are original and changes empty?

0 likes
3 replies
IgorHrcek's avatar

This is their magic:

    /**
     * Create a new action event instance for a resource update.
     *
     * @param  \Illuminate\Contracts\Auth\Authenticatable  $user
     * @param  \Illuminate\Database\Eloquent\Model  $model
     * @return \Illuminate\Database\Eloquent\Model
     */
    public static function forResourceUpdate($user, $model)
    {
        return new static([
            'batch_id' => (string) Str::orderedUuid(),
            'user_id' => $user->getAuthIdentifier(),
            'name' => 'Update',
            'actionable_type' => $model->getMorphClass(),
            'actionable_id' => $model->getKey(),
            'target_type' => $model->getMorphClass(),
            'target_id' => $model->getKey(),
            'model_type' => $model->getMorphClass(),
            'model_id' => $model->getKey(),
            'fields' => '',
            'original' => array_intersect_key($model->getOriginal(), $model->getDirty()),
            'changes' => $model->getDirty(),
            'status' => 'finished',
            'exception' => '',
        ]);
    }

in Laravel\Nova\Actions\ActionEvent. It is quite clear that they are trying to fill original and changes fields, but somehow it fails and I am not sure why.

What I can do is the following:

    public function handle(ActionFields $fields, Collection $models)
    {
        foreach ($models as $model) {
            $model->ptr = Ptr::check($model->address);
	    $actionEvent = ActionEvent::forResourceUpdate(auth()->user(), $model);
            $model->save();
            $actionEvent->save();
        }

        return Action::message('It worked!');
    }

But then I'll have two lines in the log - one for the Action and other for the Update itself and it is ugly and I do not like it. So there must be a way to somehow make it populate the fields in the first place.

906labs's avatar

@kudtihaex If you turn off logging by setting $withoutActionEvents to true in the action class, only one log entry should be created through your manual ActionEvent::forResourceUpdate() call.

Please or to participate in this conversation.