owen-it / laravel-auditing

Record the change log from models in Laravel
https://laravel-auditing.com
MIT License
3.05k stars 390 forks source link

Audit Formatting Doesn't Include Attribute Accessors #828

Open hamedghaderi opened 1 year ago

hamedghaderi commented 1 year ago
Q A
Bug? yes
New Feature? no yes
Framework Laravel Lumen
Framework version 10.8.0
Package version 13.5.0
PHP version 8.2

Actual Behaviour

Currently, when the Audit functionality formats data, it fails to detect and include attribute accessors of type "Attribute" during the formatting process. As a result, attribute accessors are not considered when formatting the data.

Expected Behaviour

It is expected that the Audit functionality should include attribute accessors of type "Attribute" during the data formatting process. This would ensure that any custom formatting defined through attribute accessors is properly considered.

Steps to Reproduce

  1. Assume we have a model Foo with a JSON attribute, bar, casted as an ArrayObject:
class Foo extends Model implements Auditable 
{
  protected $casts = [
     'bar' => AsArrayObject::class,
  ];
}
  1. Before fetching the bar attribute, we add custom formatting using an attribute accessor:

    public function bar(): Attribute
    {
    return Attribute::make(
    get: fn ($value) => // Some custom formatting 
    )
    }
  2. The Audit functionality currently ignores this custom formatting because it only checks for attribute accessors starting with get, such as getBarAttribute.

Screenshot 2023-05-16 at 11 33 46 AM