Filament Activity Logger to show old and new values

Right now I see only the new value. But I don't see the old one. Does it log only the new value that has been changed?
18 Replies
Wirkhof
Wirkhof6mo ago
Filament
Logger by ZedoX - Filament
Extensible activity logger for filament that works out-of-the-box.
Wirkhof
Wirkhof6mo ago
and it is not showing the old value. Only the new. I have tried updating the user's name many times but only see the newly updated name, not the original name it had before the change. In the table column properties I see only this {"name": "User Changed 3rd", "updated_at": "2023-12-20 00:35:37"} I don't see any "old" Why is that? It should track even the old values, right?
Wirkhof
Wirkhof6mo ago
Should. I try another activity logger? I see this one https://filamentphp.com/plugins/pxlrbt-activity-log
Filament
Activity Log by Dennis Koch - Filament
Add a Filament page that nicely shows your spatie/laravel-activitylog.
Wirkhof
Wirkhof6mo ago
Will it work better? According to docs it should return:
[
'attributes' => [
'name' => 'updated name',
'text' => 'Lorum',
],
'old' => [
'name' => 'original name',
'text' => 'Lorum',
],
];
[
'attributes' => [
'name' => 'updated name',
'text' => 'Lorum',
],
'old' => [
'name' => 'original name',
'text' => 'Lorum',
],
];
Why the json in the db doesn't have old ? OK, so this seems to be intentional.
Wirkhof
Wirkhof6mo ago
GitHub
Missing saved old value when update a resource · Issue #85 · Z3d0X/...
While testing the package functionalities, I noticed that the old values are missing when updating a resource. By this, I mean that in the spatie-activity log, when I update a resource, it saves th...
Wirkhof
Wirkhof6mo ago
Anyway, does anybody know what the author mean by this:
Hi it was an intentional choice to keep this very simple... You could disable the resource loggers and use the logging functionality provided by the base spatie-activity log
? How do I "disable the resource loggers" ? What is meant by resource loggers?
DariusIII
DariusIII6mo ago
You can enable and disable what you wan't to log in config file of the activity logger
Wirkhof
Wirkhof6mo ago
How? Can you help a bit, please? In which file? In config/activitylog.php ?
DariusIII
DariusIII6mo ago
Wirkhof
Wirkhof6mo ago
Thanks, and what should I put there if I want old values and not only new values on updates?
DariusIII
DariusIII6mo ago
I believe you can only enable and disable what is logged. Based on dev response, you should publish spatie package config file and then change things there
Wirkhof
Wirkhof6mo ago
So, in the file config/activitylog.php I have this:
<?php

return [

/*
* If set to false, no activities will be saved to the database.
*/
'enabled' => env('ACTIVITY_LOGGER_ENABLED', true),

/*
* When the clean-command is executed, all recording activities older than
* the number of days specified here will be deleted.
*/
'delete_records_older_than_days' => 365,

/*
* If no log name is passed to the activity() helper
* we use this default log name.
*/
'default_log_name' => 'default',

/*
* You can specify an auth driver here that gets user models.
* If this is null we'll use the current Laravel auth driver.
*/
'default_auth_driver' => null,

/*
* If set to true, the subject returns soft deleted models.
*/
'subject_returns_soft_deleted_models' => false,

/*
* This model will be used to log activity.
* It should implement the Spatie\Activitylog\Contracts\Activity interface
* and extend Illuminate\Database\Eloquent\Model.
*/
'activity_model' => \Spatie\Activitylog\Models\Activity::class,

/*
* This is the name of the table that will be created by the migration and
* used by the Activity model shipped with this package.
*/
'table_name' => 'activity_log',

/*
* This is the database connection that will be used by the migration and
* the Activity model shipped with this package. In case it's not set
* Laravel's database.default will be used instead.
*/
'database_connection' => env('ACTIVITY_LOGGER_DB_CONNECTION'),
];
<?php

return [

/*
* If set to false, no activities will be saved to the database.
*/
'enabled' => env('ACTIVITY_LOGGER_ENABLED', true),

/*
* When the clean-command is executed, all recording activities older than
* the number of days specified here will be deleted.
*/
'delete_records_older_than_days' => 365,

/*
* If no log name is passed to the activity() helper
* we use this default log name.
*/
'default_log_name' => 'default',

/*
* You can specify an auth driver here that gets user models.
* If this is null we'll use the current Laravel auth driver.
*/
'default_auth_driver' => null,

/*
* If set to true, the subject returns soft deleted models.
*/
'subject_returns_soft_deleted_models' => false,

/*
* This model will be used to log activity.
* It should implement the Spatie\Activitylog\Contracts\Activity interface
* and extend Illuminate\Database\Eloquent\Model.
*/
'activity_model' => \Spatie\Activitylog\Models\Activity::class,

/*
* This is the name of the table that will be created by the migration and
* used by the Activity model shipped with this package.
*/
'table_name' => 'activity_log',

/*
* This is the database connection that will be used by the migration and
* the Activity model shipped with this package. In case it's not set
* Laravel's database.default will be used instead.
*/
'database_connection' => env('ACTIVITY_LOGGER_DB_CONNECTION'),
];
Which code should I add to this file to log old values as well?
Wirkhof
Wirkhof6mo ago
So, it's not done in config file? I have to add some code in User.php model file and each other model file e.g. Product.php or Book.php? I would like to track the old and new file like you see in Denis Koch's plugin screenshot.
Wirkhof
Wirkhof6mo ago
@ZedoX You can see Old column and New column. Is that possible in your activity logger too? If yes, what is the easiest way to do that? Meaning write it preferable once in some file and apply to all models/resources.
ZedoX
ZedoX6mo ago
You have a few options if you want to show old & new properties 1) Replace \Z3d0X\FilamentLogger\Loggers\ResourceLogger::class with your own logger (you can see this file for the current implementation https://github.com/Z3d0X/filament-logger/blob/main/src/Loggers/AbstractModelLogger.php) 2) in the filament-logger.php config file disable the https://github.com/Z3d0X/filament-logger/blob/main/config/filament-logger.php#L9. Then use configure your models for using the base spatie's activity log package https://spatie.be/docs/laravel-activitylog/v2/advanced-usage/logging-model-events
Wirkhof
Wirkhof6mo ago
It seems I will try Denis Koch's plugin before starting writing a custom code as you are suggesting. @ZedoX Do I need to uninstall/rollback your plugin before installing Denis Koch's activity logger? Or could I have both running at the same time?