glaivepro / drafterer
Drafting upcoming versions for Eloquent models
Requires
- php: ~7.1
- illuminate/database: ~5.5
- illuminate/support: ~5.5
Requires (Dev)
- phpunit/phpunit: >=5.4.3
- squizlabs/php_codesniffer: ^2.3
This package is auto-updated.
Last update: 2020-10-07 07:16:54 UTC
README
The development of this package is a bit postponed for now because of lack of time.
Drafterer is a Laravel package that allows you to save a draft version of an Eloquent model. It can be used for previewing upcoming changes before commiting them. Also useful for autosaved version.
Install
Via Composer.
$ composer require glaivepro/drafterer
Afterwards you should migrate the table for drafts. Just do it.
$ php artisan migrate
Usage
Make your model draftable.
use Illuminate\Database\Eloquent\Model; use GlaivePro\Drafterer\Draftable; class Article extends Model { use Draftable; // }
Save changes as a draft instead of the model itself.
$article = Article::find(1); $article->title = 'Real title'; $article->intro = 'Real introduction'; $article->save(); $article->title = 'Draft title'; $article->drafterer->save();
Use the real or drafted article.
$article = Article::find(1); $article->title; // returns 'Real title' $article->drafterer->title; // returns 'Draft title' $article->drafterer->intro; // returns 'Real introduction'
You might want to decide to use the draft as the real version - just write it down then.
$article->drafterer->write();
Or you might discard it.
$article->drafterer->discard();
For draft-only users or conditionals we can also replace the attributes with the drafted ones.
$article->title; // returns 'Real title' $article->drafterer->load(); $article->title; // returns 'Draft title'
Change log
Please see CHANGELOG for more information on what has changed recently.
Security
If you discover any security related issues, please email juris@glaive.pro instead of using the issue tracker.
License
The MIT License (MIT). Please see License File for more information.