A Simple Draft and Revision System for Laravel
Laravel Drafts is a simple drop-in draft and revision system for Eloquent models. This package also supports drafts for related models; you can control saving models in a published or draft mode.
To get started with this package, your project will use the provided
4class Post extends Model
6 use HasDrafts;
7 // ...
With the trait configured, you can use the following API to control creating a published model or a draft:
1// By default, the record is published
3 'title' => 'Foo',
4 // ...
7// You can set the record as a draft in a few different ways:
9// Via the `is_published` flag
11 'title' => 'Foo',
12 'is_published' => false,
15// Calling `createDraft`
16Post::createDraft(['title' => 'Foo']);
18// Using the `saveAsDraft` method on a model
19Post::make(['title' => 'Foo'])->saveAsDraft();
Similarly, you can update a model, keeping it as a draft:
1$post->updateAsDraft(['title' => 'Bar']);
5$post->title = 'Bar';
You can also access draft revisions and configure how many total revisions to keep in the database. The readme is an excellent place to get started with this package.
Check out this package and contribute on GitHub at oddvalue/laravel-drafts.
Credit: Source link