This is an old revision of the document!
Laravel Audit
Install
composer require spatie/laravel-activitylog php artisan vendor:publish --provider="Spatie\Activitylog\ActivitylogServiceProvider" --tag="migrations" php artisan vendor:publish --provider="Spatie\Activitylog\ActivitylogServiceProvider" --tag="config" php artisan config:cache php artisan migrate
Logging Model Events
use Spatie\Activitylog\Traits\LogsActivity; class User extends Authenticatable implements LdapAuthenticatable { // use LogsActivity; protected $fillable = [ 'name', 'username', 'pin', 'pin_expiry_date', 'mobile' ]; //protected static $logFillable = true; // This would log all fillable. // But to reduce what we see in the log (an example below), we will use statically state exactly what we want to log. // {"attributes":{"name":"Richard Strong","username":"G12302","pin":"3680","pin_expiry_date":"2021-04-25T23:00:00.000000Z","mobile":"0851231234"},"old":{"name":"Richard Dunne","username":"G12302","pin":"3680","pin_expiry_date":"2021-04-25T23:00:00.000000Z","mobile":null}} protected static $logAttributes = ['pin', 'mobile']; // This gives the following detail in the properties field - which is much tidier that all values as in above example. // {"attributes":{"pin":"3680","mobile":"0851231235"},"old":{"pin":"3680","mobile":"0851231234"}}