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

Disable or remove the standard UserResolver from being tracked to the audits #836

Closed RastaTux closed 1 year ago

RastaTux commented 1 year ago
Q A
Bug? no
New Feature? no
Framework Laravel
Framework version 10.8
Package version 13.5
PHP version 8.1

Actually it's more of a question than a bug. What I want is starting by the standard configuration of Laravel Auditing to exclude the user (id and user_type) from the database and only save the email of a user. My attempt was to comment the entire User morph stuff:

/*'user' => [ 'morph_prefix' => 'user', 'guards' => [ 'web', 'api' ], 'resolver' => OwenIt\Auditing\Resolvers\UserResolver::class ],*/

and add my own resolver 'user_email' => App\AuditResolvers\UseremailResolver::class to the resolvers array. Also, I changed the migration, removed the user_id and user_type and added user_email. But this however brings me to the following behaviour:

Actual Behaviour

The user_id column is still present in the INSERT INTO audits query. Error: Column not found: 1054 Unknown column 'user_id' in 'field list'.

Expected Behaviour

Only add insert columns to the query that are listed under the resolvers.

Steps to Reproduce

All that is needed is to comment the entiry user array from the audit.php, as mentioned above.

Possible Solutions

I guess, I need to do more to prevent that from happening and I hope, Laravel Auditing is flexible enough to exlude the User stuff completely. Just commenting out the user array won't stop Laravel Auditing from trying to add user information. However, another possible solution might be to alter the UserResolver to get that behaviour.

parallels999 commented 1 year ago

For questions there is a discussions section