Manage model revisions with ease.
If you are also looking to preview the form data before submitting to the db, you may want to give OverSeer a try.
- package requires Laravel v5.4+
-
composer require ctf0/odin -
(Laravel < 5.5) add the service provider & facade
'providers' => [ ctf0\Odin\OdinServiceProvider::class, ];
-
publish the package assets with
php artisan vendor:publish --provider="ctf0\Odin\OdinServiceProvider"
-
after installation, package will auto-add
- package routes to
routes/web.php - package assets compiling to
webpack.mix.js
- package routes to
-
check http://www.laravel-auditing.com/docs/7.0/general-configuration for configuration
-
install dependencies
yarn add vue vue-awesome@v2 vue-notif axios keycode # or npm install vue vue-awesome@v2 vue-notif axios keycode --save -
add this one liner to your main js file and run
npm run watchto compile yourjs/cssfiles.- if you are having issues Check.
// app.js window.Vue = require('vue') require('../vendor/Odin/js/manager') new Vue({ el: '#app' })
-
support single & nested values.
-
delete & restore revisions.
-
don't save the audit record if the model
old_value & new_valueare empty. -
support soft deletes.
-
clear audits for permanently deleted models.
php artisan odin:gc
- which can be scheduled as well
$schedule->command('odin:gc')->sundays();
-
shortcuts
navigation keyboard mouse (click) go to next revision right/down * (revision date) go to prev revision left/up * (revision date) go to first revision home * (revision date) go to last revision end * (revision date) hide revision window esc * (x) -
events "JS"
event-name description odin-show when revision is showen odin-hide when revision is hidden
-
run
php artisan migrate -
add
Revisionstrait &AuditableContractcontract to your model- for
User modelCheck
use ctf0\Odin\Traits\Revisions; use Illuminate\Database\Eloquent\Model; use OwenIt\Auditing\Contracts\Auditable as AuditableContract; class Post extends Model implements AuditableContract { use Revisions; /** * resolve model title/name for the revision relation * this is needed so we can render * the model relation attach/detach changes */ public function getMiscTitleAttribute() { return $this->name; } // ... }
- for
-
you can disable creating ghost audits where both
old/newvalues are empty by using- remember that without the parent model audit log we cant show the relation changes
// app/Providers/EventServiceProvider use OwenIt\Auditing\Models\Audit; public function boot() { parent::boot(); Audit::creating(function (Audit $model) { if (empty($model->old_values) && empty($model->new_values)) { return false; } }); }
-
inside the model view ex.
post edit viewadd@if (count($post->revisionsWithRelation)) @include('Odin::list', ['revisions' => $post->revisionsWithRelation]) @endif
-
model
user_id&idare excluded from the audit log by default. -
data:uri
-
if you use
data:uriin your revisionable content, changeaudits_tablecolumns type to eithermediumTextorlongTextbefore migrating to avoid future errors of long data. -
because
data:uriis a render blocking & isn't readable by humans, we truncate it to 75 char max (the smallest stable data:uri is 78 char),
note that this ONLY effects the displaying of the revision diff, we never touch the data that gets saved to the db.
-
-
model-relation
- atm the relation revision is limited, it means we can only show the
attach/detachchanges but we cantundo/redoany of them through the package it self. - also if you use mass update like
Model::update()make sure to call$model->touch();afterwards to make sure an audit is created ex.$model = Model::update([...]); $model->touch();
- atm the relation revision is limited, it means we can only show the