Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unchanged properties are logged on model update #1358

Open
Jacobtims opened this issue Dec 12, 2024 · 0 comments
Open

Unchanged properties are logged on model update #1358

Jacobtims opened this issue Dec 12, 2024 · 0 comments
Labels

Comments

@Jacobtims
Copy link

Describe the bug
When I update my model (that uses the LogsActivity trait) the Activity record contains properties that weren't updated. The properties "old" array contains null values and the "attributes" array contains attributes that weren't updated.

To Reproduce
I have the following options in my model:

public function getActivitylogOptions(): LogOptions
{
    return LogOptions::defaults()
        ->logUnguarded()
        ->logOnlyDirty()
        ->dontSubmitEmptyLogs()
        ->dontLogIfAttributesChangedOnly(['updated_at']);
}

Example of an update:

// Retrieve a random model
$myModel = \App\Models\MyModel::first();

$myModel->fill([
    'timezone' => 'UTC',
]);

$myModel->save();

// Retrieve the latest log
$log = \Spatie\Activitylog\Models\Activity::where('description', 'updated')->latest()->first()?->toArray();

dd($log, $myModel);

Activity log:
Image

Expected behavior
I expect that the Activity record only contains properties that where updated.
In my case only the "timezone" property.

Versions

  • PHP: 8.2.26
  • Database: mysql
  • Laravel: 11.35.0
  • Package: 4.9.1
@Jacobtims Jacobtims added the bug label Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant