d

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore.

15 St Margarets, NY 10033
(+381) 11 123 4567
ouroffice@aware.com

 

KMF

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 HasDrafts trait:

1use IlluminateDatabaseEloquentModel;

2use OddvalueLaravelDraftsConcernsHasDrafts;

3 

4class Post extends Model

5{

6 use HasDrafts;

7 // ...

8}

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

2Post::create([

3 'title' => 'Foo',

4 // ...

5]);

6 

7// You can set the record as a draft in a few different ways:

8 

9// Via the `is_published` flag

10Post::create([

11 'title' => 'Foo',

12 'is_published' => false,

13]);

14 

15// Calling `createDraft`

16Post::createDraft(['title' => 'Foo']);

17 

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']);

2 

3// Or

4 

5$post->title = 'Bar';

6$post->saveAsDraft();

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

Previous Next
Close
Test Caption
Test Description goes like this