spatie / laravel-activitylog

Log activity inside your Laravel app

Home Page:https://docs.spatie.be/laravel-activitylog

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

useAttributeRawValues ignores attribute mutation

debuqer opened this issue · comments

Describe the bug
As far as i know, attributesToBeLogged always contains mutated data, but when ActivityLog suppose to ignore casts, using useAttributeRawValues(), mutation method will ignore

To Reproduce

it('can ignore cast and store mutated value while attribute has mutator', function () {
    $articleClass = new class() extends Article {
        use LogsActivity;

        protected $casts = [
            'status' => 'string',
        ];

        public function getStatusAttribute($value)
        {
            return $value ? 'Show' : 'Hide';
        }

        public function getActivitylogOptions(): LogOptions
        {
            return LogOptions::defaults()->logOnly(['status'])->useAttributeRawValues(['status']);
        }
    };

    $article = new $articleClass();
    $article->status = 1;
    $article->save();

    $this->assertEquals($article->status, $this->getLastActivity()->properties['attributes']['status']); // expected 'Show' but '1' given
});

If you use useAttributeRawValues(['status'])

"attributes" =>  [
      "status" => 1
    ]

If you use useAttributeRawValues([])

"attributes" =>  [
      "status" => "Show"
    ]

Versions

  • PHP: 8.0
  • Database: mysql

I'm not sure if its correct behavior or not, but based on documentation useAttributeRawValues let ActivityLog to store the data without casting and it's just not about mutation.

Dear contributor,

because this issue seems to be inactive for quite some time now, I've automatically closed it. If you feel this issue deserves some attention from my human colleagues feel free to reopen it.