PHPackages                             leandrodiogenes/laravel-drafts - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. leandrodiogenes/laravel-drafts

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

leandrodiogenes/laravel-drafts
==============================

A simple, drop-in drafts/revisions system for Laravel models

v0.0.4(3y ago)0331MITPHPPHP ^7.4

Since Jun 28Pushed 3y agoCompare

[ Source](https://github.com/leandrodiogenes/laravel-drafts)[ Packagist](https://packagist.org/packages/leandrodiogenes/laravel-drafts)[ Docs](https://github.com/oddvalue/laravel-drafts)[ RSS](/packages/leandrodiogenes-laravel-drafts/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (16)Versions (5)Used By (0)

[![](https://camo.githubusercontent.com/d245c1a46f7f16c560b66ea46f55b41732eea1a8eb5bb0336836c9ccfae00715/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f4c61726176656c2532304472616674732e706e673f7468656d653d6461726b267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d6f646476616c75652532466c61726176656c2d647261667473267061747465726e3d617263686974656374267374796c653d7374796c655f31266465736372697074696f6e3d412b73696d706c652532432b64726f702d696e2b6472616674732532467265766973696f6e732b73797374656d2b666f722b4c61726176656c2b6d6f64656c73266d643d312673686f7757617465726d61726b3d3126666f6e7453697a653d313030707826696d616765733d68747470732533412532462532466c61726176656c2e636f6d253246696d672532466c6f676f6d61726b2e6d696e2e737667 "Laravel Drafts")](https://camo.githubusercontent.com/d245c1a46f7f16c560b66ea46f55b41732eea1a8eb5bb0336836c9ccfae00715/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f4c61726176656c2532304472616674732e706e673f7468656d653d6461726b267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d6f646476616c75652532466c61726176656c2d647261667473267061747465726e3d617263686974656374267374796c653d7374796c655f31266465736372697074696f6e3d412b73696d706c652532432b64726f702d696e2b6472616674732532467265766973696f6e732b73797374656d2b666f722b4c61726176656c2b6d6f64656c73266d643d312673686f7757617465726d61726b3d3126666f6e7453697a653d313030707826696d616765733d68747470732533412532462532466c61726176656c2e636f6d253246696d672532466c6f676f6d61726b2e6d696e2e737667)

A simple, drop-in drafts/revisions system for Laravel models
============================================================

[](#a-simple-drop-in-draftsrevisions-system-for-laravel-models)

[![Latest Version on Packagist](https://camo.githubusercontent.com/74dbf5de245604b4d1267de7efc0fc07f866ee01ea5508b6385c97f32fe04eb3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6f646476616c75652f6c61726176656c2d6472616674732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/oddvalue/laravel-drafts)[![GitHub Tests Action Status](https://camo.githubusercontent.com/818277cab23dc6d7ea0531e6becdc222f0406a2a010d1b9ebfacbdc97c9e39c6/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f6f646476616c75652f6c61726176656c2d6472616674732f72756e2d74657374733f6c6162656c3d7465737473)](https://github.com/oddvalue/laravel-drafts/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/0623983bf8c39d2827fbc27d84b48ffb8c0f03c8bc11dfaeafadde754cc0d3a6/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f6f646476616c75652f6c61726176656c2d6472616674732f436865636b253230262532306669782532307374796c696e673f6c6162656c3d636f64652532307374796c65)](https://github.com/oddvalue/laravel-drafts/actions?query=workflow%3A%22Check+%26+fix+styling%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/d35048067a4234303c554140b6cca076953230e48fa71d3b77f9591aecd57a8c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6f646476616c75652f6c61726176656c2d6472616674732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/oddvalue/laravel-drafts)

- [Installation](#installation)
- [Usage](#usage)
    - [Preparing your models](#preparing-your-models)
        - [Add the trait](#add-the-trait)
        - [Relations](#relations)
        - [Database](#database)
    - [The API](#the-api)
        - [Creating a new record](#creating-a-new-record)
        - [Relations](#relations)
    - [Interacting with records](#interacting-with-records)
        - [Published revision](#published-revision)
        - [Current Revision](#current-revision)
- [Testing](#testing)
- [Changelog](#changelog)
- [Contributing](#contributing)
- [Security Vulnerabilities](#security-vulnerabilities)
- [Credits](#credits)
- [License](#license)

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require oddvalue/laravel-drafts
```

You can publish the config file with:

```
php artisan vendor:publish --tag="laravel-drafts-config"
```

This is the contents of the published config file:

```
return [
    'revisions' => [
        'keep' => 10,
    ],

    'column_names' => [
        /*
         * Boolean column that marks a row as the current version of the data for editing.
         */
        'is_current' => 'is_current',

        /*
         * Boolean column that marks a row as live and displayable to the public.
         */
        'is_published' => 'is_published',

        /*
         * Timestamp column that stores the date and time when the row was published.
         */
        'published_at' => 'published_at',

        /*
         * UUID column that stores the unique identifier of the model drafts.
         */
        'uuid' => 'uuid',

        /*
         * Name of the morph relationship to the publishing user.
         */
        'publisher_morph_name' => 'publisher',
    ],

    'auth' => [
        /*
         * The guard to fetch the logged-in user from for the publisher relation.
         */
        'guard' => 'web',
    ],
];
```

Usage
-----

[](#usage)

### Preparing your models

[](#preparing-your-models)

#### Add the trait

[](#add-the-trait)

Add the `HasDrafts` trait to your model

```
