pderas/archivalist
| Install | |
|---|---|
composer require pderas/archivalist |
|
| Latest Version: | v2.2.0 |
| PHP: | ^7.3|^8.0 |
| License: | MIT |
| Last Updated: | Mar 9, 2023 |
| Links: | GitHub · Packagist |
Archivalist
Archivalist is a minimal package designed to make archiving changes to Laravel models easy.
Installation
You can install the package via composer:
composer require pderas/archivalist
Usage
Simply add the Pderas\Archivalist\Traits\HasArchives to any model you wish to archive.
use Pderas\Archivalist\Traits\HasArchives;
class Post extends Model {
use HasArchives;
}
If you wish certain columns to always be archived, this can be accomplished by adding wither a archived property or method to the model
use Pderas\Archivalist\Traits\HasArchives;
class Post extends Model {
use HasArchives;
protected $archived = [
'updated_at'
];
// Alternatively...
protected function archived() {
return [
'updated_at' => $this->getOriginal('updated_at'),
'is_archived' => true
];
}
}
Archives can be 'rehydrated' into the state of the original model
$user->company = 'Pderas';
$user->save();
$archive = $user->archives()->first(); // => \Pderas\Archivalist\Models\Archive
$original = $archive->rehydrate(); // => \App\User
A Collection with the full history of the model can be acquired using ->getHistory()
$user->getHistory(); // A user model for every state the user was in
Mass assignment is not supported, in which case you must use the following workaround:
// Do not do
Post::where('status','open')
->update(['status','closed']); // This will fail
// Do this instead
Archivalist::proxy(Post::query())
->where('status','open')
->update(['status','closed']);
Support for beforeArchive has been added. Implement the method beforeArchive on any model which uses HasArchives trait to run any extra logic before the primary archives logic is ran.
// SomeModel which uses HasArchives
public function beforeArchive() {
// Put logic here to be ran before the primary archives logic is ran
// useful for automating tasks such as always writing user->id, etc
}
Testing
composer test
Changelog
Please see CHANGELOG for more information what has changed recently.
Security
If you discover any security related issues, please email reed.jones@pderas.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
Related Packages
Powerful PHP database abstraction layer (DBAL) with many features for database s...
Laravel Serializable Closure provides an easy and secure way to serialize closur...
Cli error handling for console/command-line PHP applications.
Version History
| Version | Released | PHP | Laravel | License |
|---|---|---|---|---|
| v2.2.0 | ^7.3| | ^6.0| | MIT | |
| v2.0.0 | ^7.3 | ^6.0| | MIT | |
| v1.0.1 | ^7.3 | ^6.0| | MIT | |
| v1.0.0 | ^7.3 | ^6.0| | MIT | |
| v0.2.3 | ^7.3 | ^6.0| | MIT | |
| v0.2.2 | ^7.3 | ^6.0| | MIT | |
| v0.2.1 | ^7.3 | ^6.0| | MIT | |
| v0.2.0 | ^7.3 | ^6.0| | MIT | |
| v0.1.0 | ^7.3 | ^6.0| | MIT |