rickyjohnston / fingerprints
Make your admins leave their fingerprints all over Eloquent Model changes
Installs: 1
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/rickyjohnston/fingerprints
Requires
- php: >=7.1
- illuminate/contracts: ~5.6|~5.7
- illuminate/database: ~5.6|~5.7
- illuminate/queue: ~5.6|~5.7
- illuminate/support: ~5.6|~5.7
Requires (Dev)
- orchestra/testbench: ~3.6
- phpunit/phpunit: ^6.2|^7.0
This package is auto-updated.
Last update: 2025-10-23 14:23:51 UTC
README
Keep track of which Admins touch your Laravel Eloquent models.
Installation
via composer:
composer require rickyjohnston/fingerprints
Usage
This package provides a new abstract class for your model to extend. Swap out Model for TrackableModel.
<?php namespace App; use RickyJohnston\Fingerprints\TrackableModel; class ExampleModel extends TrackableModel { // ... }
By doing this, your model will automatically dispatch Fingerprints' custom Events on create and update. Additionally, a creator() and updater() relationship will be assigned to the model (both referencing the App\User model).
Since this package is using events and listeners, head to your EventServiceProvider and add these new objects to the $listen array.
//.. use RickyJohnston\Fingerprints\Events\ModelCreated; use RickyJohnston\Fingerprints\Events\ModelUpdated; use RickyJohnston\Fingerprints\Listeners\AddCreatorToModel; use RickyJohnston\Fingerprints\Listeners\AddUpdaterToModel; class EventServiceProvider extends ServiceProvider { /** * The event listener mappings for the application. * * @var array */ protected $listen = [ ModelCreated::class => [ AddCreatorToModel::class, ], ModelUpdated::class => [ AddUpdaterToModel::class, ], // ... ]; }
Finally, Fingerprints registers a macro on the Blueprint class, allowing you to use a new method inside your migrations. Add the fingerprints() method to your model Migrations to create the created_by and updated_by columns:
Schema::create('posts', function (Blueprint $table) { $table->increments('id'); $table->text('message'); $table->fingerprints(); $table->timestamps(); });
For the down() method inside migrations, dropFingerprints() also exists.