PHPackages                             oddvalue/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. oddvalue/laravel-drafts

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

oddvalue/laravel-drafts
=======================

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

v3.0.0(3mo ago)423196.1k—8.4%21[1 PRs](https://github.com/oddvalue/laravel-drafts/pulls)2MITPHPPHP ^8.0CI passing

Since Jun 28Pushed 1mo ago4 watchersCompare

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

READMEChangelog (10)Dependencies (17)Versions (29)Used By (2)

[![](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)[![PHP Support](https://camo.githubusercontent.com/c95b73da5a1a5da10214ee7519be44e6a8b7baaee48b8a71a5371096c763d565/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f64796e616d69632f6a736f6e3f75726c3d68747470732533412532462532467261772e67697468756275736572636f6e74656e742e636f6d2532466f646476616c75652532466c61726176656c2d6472616674732532466d61696e253246636f6d706f7365722e6a736f6e2671756572793d726571756972652e706870266c6162656c3d504850)](https://camo.githubusercontent.com/c95b73da5a1a5da10214ee7519be44e6a8b7baaee48b8a71a5371096c763d565/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f64796e616d69632f6a736f6e3f75726c3d68747470732533412532462532467261772e67697468756275736572636f6e74656e742e636f6d2532466f646476616c75652532466c61726176656c2d6472616674732532466d61696e253246636f6d706f7365722e6a736f6e2671756572793d726571756972652e706870266c6162656c3d504850)[![Laravel Support](https://camo.githubusercontent.com/895add718d8f02429875a13a3cb848034c115070053e7d9ce2b04ab9dc62d104/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f64796e616d69632f6a736f6e3f75726c3d68747470732533412532462532467261772e67697468756275736572636f6e74656e742e636f6d2532466f646476616c75652532466c61726176656c2d6472616674732532466d61696e253246636f6d706f7365722e6a736f6e2671756572793d7265717569726525354227696c6c756d696e617465253246636f6e74726163747327253544266c6162656c3d4c61726176656c)](https://camo.githubusercontent.com/895add718d8f02429875a13a3cb848034c115070053e7d9ce2b04ab9dc62d104/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f64796e616d69632f6a736f6e3f75726c3d68747470732533412532462532467261772e67697468756275736572636f6e74656e742e636f6d2532466f646476616c75652532466c61726176656c2d6472616674732532466d61696e253246636f6d706f7365722e6a736f6e2671756572793d7265717569726525354227696c6c756d696e617465253246636f6e74726163747327253544266c6162656c3d4c61726176656c)[![GitHub Tests Action Status](https://camo.githubusercontent.com/c4e55d9ce82bfa0cbf1bafa714bd77cbdec82606ecd1d0f2c62fd2335c281e97/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6f646476616c75652f6c61726176656c2d6472616674732f72756e2d74657374732e796d6c3f6c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/oddvalue/laravel-drafts/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/689efbb5e0ba836a3ec7c11db23c79ee75095811c436d96dacb63e281f40a1fd/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6f646476616c75652f6c61726176656c2d6472616674732f7068702d63732d66697865722e796d6c3f6c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](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)[![Coverage](https://camo.githubusercontent.com/7d5e02faf9c3f57af6bf169ecba042f9ea27323627de2ed345422d9a51cd1dae/68747470733a2f2f696d672e736869656c64732e696f2f656e64706f696e743f75726c3d68747470733a2f2f676973742e67697468756275736572636f6e74656e742e636f6d2f6f646476616c75652f39646438653530386362323433333732386434326132353831393337373065622f7261772f6c61726176656c2d6472616674732d636f626572747572612d636f7665726167652e6a736f6e)](https://camo.githubusercontent.com/7d5e02faf9c3f57af6bf169ecba042f9ea27323627de2ed345422d9a51cd1dae/68747470733a2f2f696d672e736869656c64732e696f2f656e64706f696e743f75726c3d68747470733a2f2f676973742e67697468756275736572636f6e74656e742e636f6d2f6f646476616c75652f39646438653530386362323433333732386434326132353831393337373065622f7261772f6c61726176656c2d6472616674732d636f626572747572612d636f7665726167652e6a736f6e)

- [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)
        - [Revisions](#revisions)
        - [Preview mode](#preview-mode)
    - [Middleware](#middleware)
        - [WithDraftsMiddleware](#withdraftsmiddleware)
- [Testing](#testing)
- [Changelog](#changelog)
- [Contributing](#contributing)
- [Security Vulnerabilities](#security-vulnerabilities)
- [Credits](#credits)
- [License](#license)

Version compatibility
---------------------

[](#version-compatibility)

LaravelDraftsv9.xv1.xv10.xv1.xv11.xv2.xv12.x&gt;2.1Installation
------------

[](#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="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

```
