Download the PHP package ferdiunal/eloquent-history without Composer
On this page you can find all versions of the php package ferdiunal/eloquent-history. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package eloquent-history
Installation
Composer
Laravel 9.x and above
config/app.php
Migration
Config
Localization
Usage
Add HasOperations
trait to user model.
Add HasHistories
trait to the model that will be tracked.
Remember that you'll need to implement the abstract getModelLabel
method from the trait.
This provides the model instance's name in histories.
Get histories of a model
Get operations of a user
Additional query conditions
Both histories
and operations
return Eloquent relationships which also serve as query builders. You can add further constraints by chaining conditions:
History
Example message
Example meta
Custom history
Besides the built in created/updating/deleting/restoring
events, you may store custom history record with ModelChanged
event.
The ModelChanged
constructor accepts two/three arguments. The first is the associated model instance; the second is the message; the third is optional, which is the meta(array);
Localization
You may localize the model's type name.
To do that, add the language line to the models
array in the published language file, with the key being the class's base name in snake case.
Example language config
This will translate your model history into
Filters
You may set whitelist and blacklist in config file. Please follow the description guide in the published config file.
Auth guards
If your users are using non-default auth guards, you might see all $history->hasUser()
become false
even though the history sources were generated by authenticated users.
To fix this, you'll need to enable custom auth guards scanning in config file:
Custom meta
You can define your own method for meta data. By default for updating
event meta consists of modified keys and for other events meta is null
.
Just redefine the method getModelMeta
for the trait.
Example:
Known issues
- When updating a model, if its model label(attributes returned from
getModelLabel
) has been modified, the history message will use its new attributes, which might not be what you expect.
A workaround