Download the PHP package panoscape/history without Composer
On this page you can find all versions of the php package panoscape/history. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package history
History
Eloquent model history tracking for Laravel
Installation
Composer
Laravel 6.x and above
Laravel 5.6.x
Service provider and alias
Only required for Laravel 5.6.x
config/app.php
Migration
Config
Localization
Usage
Add HasOperations
trait to user model that performs operations.
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 display name in histories (as Who
in Who did what
).
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 track custom history record by firing an ModelChanged
event.
The ModelChanged
constructor accepts two/three/four arguments. The first is the associated model instance; the second is the message; the third is optional, which is the meta(array); the fourth is also optional, being the translation key of the event(see Localization).
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
You can also translate custom history messages from ModelChanged
events
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
All versions of history with dependencies
illuminate/support Version ^6.0|^7.0|^8.0|^9.0|^10.0|^11.0