{"_id":"570dfaa5b5e70e3200b7bce0","parentDoc":null,"__v":8,"user":"570df764b22f0129008dfc23","project":"563b65bd9e3f2225009fd2bc","category":{"_id":"563b6b25e951f60d000b4513","version":"563b65bd9e3f2225009fd2bf","__v":6,"pages":["563c21fd19ae7b0d0050d45b","563c220c7539dd0d00dbee87","563c2218ac77910d00279fe7","563c2233d8f2d20d00448b4f","563c2376913e650d00b65dbd","563c907319ae7b0d0050d528"],"project":"563b65bd9e3f2225009fd2bc","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-11-05T14:43:49.565Z","from_sync":false,"order":1,"slug":"the-basics","title":"The Basics"},"version":{"_id":"563b65bd9e3f2225009fd2bf","project":"563b65bd9e3f2225009fd2bc","__v":4,"createdAt":"2015-11-05T14:20:45.639Z","releaseDate":"2015-11-05T14:20:45.639Z","categories":["563b65be9e3f2225009fd2c0","563b6b25e951f60d000b4513","563c239e260dde0d00c5e890","563c2440260dde0d00c5e891"],"is_deprecated":false,"is_hidden":false,"is_beta":true,"is_stable":true,"codename":"","version_clean":"4.0.0","version":"4.0"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-04-13T07:52:05.572Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":7,"body":"The Lavalite model is capable of recording the history of changes in values by storing revisions. \n\nThe revisions can be stored for the model, you could further apply the ***Litepie\\Rivision\\Traits\\Revision*** trait and declare a ***$revision*** property with an array containing the attributes to monitor for changes. \n\nYou also need to define a ***$morphMany*** model relation called revision_history that refers to the ***Litepie\\Revision\\Models\\Revision*** class with the name ***revision***, this is where the revision history data is stored.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<?\\n\\nclass User extends Model\\n{\\n    use \\\\Litepie\\\\Rivision\\\\Traits\\\\Revision;\\n\\n    /**\\n     * :::at:::var array Monitor these attributes for changes.\\n     */\\n    protected $revision = ['name', 'email'];\\n\\n    /**\\n     * @var array Relations\\n     */\\n    public $morphMany = [\\n        'revision_history' => ['Litepie\\\\Revision\\\\Models\\\\Revision', 'name' => 'revision']\\n    ];\\n}\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nBy default 500 records will be kept, however this limit can be further modified by declaring a ***$revisionableLimit*** property on the model with a new limit value.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<?\\n\\n/**\\n * @var int Maximum number of revision records to keep.\\n */\\npublic $revisionLimit = 50;\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nThe revision history can be accessed like any other relation:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<?\\n\\n$history = User::find(1)->revision_history;\\n\\nforeach ($history as $record) {\\n    echo $record->field . ' updated ';\\n    echo 'from ' . $record->old_value;\\n    echo 'to ' . $record->new_value;\\n}\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"revision","type":"basic","title":"Revision"}
The Lavalite model is capable of recording the history of changes in values by storing revisions. The revisions can be stored for the model, you could further apply the ***Litepie\Rivision\Traits\Revision*** trait and declare a ***$revision*** property with an array containing the attributes to monitor for changes. You also need to define a ***$morphMany*** model relation called revision_history that refers to the ***Litepie\Revision\Models\Revision*** class with the name ***revision***, this is where the revision history data is stored. [block:code] { "codes": [ { "code": "<?\n\nclass User extends Model\n{\n use \\Litepie\\Rivision\\Traits\\Revision;\n\n /**\n * @var array Monitor these attributes for changes.\n */\n protected $revision = ['name', 'email'];\n\n /**\n * @var array Relations\n */\n public $morphMany = [\n 'revision_history' => ['Litepie\\Revision\\Models\\Revision', 'name' => 'revision']\n ];\n}", "language": "php" } ] } [/block] By default 500 records will be kept, however this limit can be further modified by declaring a ***$revisionableLimit*** property on the model with a new limit value. [block:code] { "codes": [ { "code": "<?\n\n/**\n * @var int Maximum number of revision records to keep.\n */\npublic $revisionLimit = 50;", "language": "php" } ] } [/block] The revision history can be accessed like any other relation: [block:code] { "codes": [ { "code": "<?\n\n$history = User::find(1)->revision_history;\n\nforeach ($history as $record) {\n echo $record->field . ' updated ';\n echo 'from ' . $record->old_value;\n echo 'to ' . $record->new_value;\n}", "language": "php" } ] } [/block]