PHPackages                             nekodev/drafty - 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. nekodev/drafty

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

nekodev/drafty
==============

Create draft for your models in Laravel

v1.0.1(5y ago)17MITPHP

Since Jul 28Pushed 5y agoCompare

[ Source](https://github.com/NekoDesigner/drafty)[ Packagist](https://packagist.org/packages/nekodev/drafty)[ RSS](/packages/nekodev-drafty/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependenciesVersions (3)Used By (0)

Drafty
======

[](#drafty)

See the complete documentation on [nekodev packages website](https://packages.nekodev.fr/laravel/drafty). (Comming soon)

Compatiable with [Spatie/MediaLibrary package v8](https://docs.spatie.be/laravel-medialibrary/v8/).

Quick Start
-----------

[](#quick-start)

### Installation

[](#installation)

install package via composer

```
composer require nekodev/drafty
```

Add provider from *config/app.php*

```
'providers' => [
    ...
    Nekodev\Drafty\DraftyServiceProvider::class,
    ...
],
```

Launch migrations

```
php artisan migrate
```

This command will create `drafts` table from your database. This table will manage all your drafts data.

Prepare your model

```
namespace App;

use Illuminate\Database\Eloquent\Model;
use Nekodev\Drafty\Traits\Draftable;
use Nekodev\Drafty\Interfaces\HasDraftable;

class Post extends Model implements HasDraftable
{
    use Draftable;

    /**
     * Get the post's draft.
     */
    public function draft()
    {
        return $this->morphOne('Nekodev\Drafty\Models\Draft', 'draftable');
    }
}
```

Draft use polymorphique relations. You must implements HasDraftable interface and use `draft()` method. This method will return a Draft class model.

### Basic usage

[](#basic-usage)

Example from controller

```
private function saveDraftPost(Request $request, Post $post)
{
    // Update Model data
    $post->title = $request->title;
    $post->content = $request->content;

    // create or update draft and return it
    $data = $post->saveAsDraft();

    return $data;
}
```

When `$post->save()` method will call, draft will automatically deleted. You **must** call `$post->applyDraft()` **before** calling `save` method.

Draft customization
-------------------

[](#draft-customization)

You can create your owns Drafts Models. `php artisan make:draft `

```
php artisan make:draft PostDraft
```

This command will create a draft méthod from *app/Drafts* directory.

```
namespace App\Drafts;

use Nekodev\Drafty\Models\Draft as DraftModel;

class PostDraft extends DraftModel
{

}
```

### Example usage

[](#example-usage)

If you whant add some relationship :

**POST MODEL**

```
namespace App;

use Illuminate\Database\Eloquent\Model;
use Nekodev\Drafty\Traits\Draftable;
use Nekodev\Drafty\Interfaces\HasDraftable;
use App\Category;

class Post extends Model implements HasDraftable
{
    use Draftable;

    public $fillable = [ 'title', 'content' ];

    /**
     * Get the post's draft.
     */
    public function draft()
    {
        return $this->morphOne('App\Drafts\PostDraft', 'draftable');
    }

    /**
     * Return categories from post
     */
    public function categories()
    {
        return $this->morphToMany('App\Category', 'categorable');
    }
}
```

**CUSTOM DRAFT MODEL**

```
namespace App\Drafts;

use Nekodev\Drafty\Models\Draft as DraftModel;
use App\Category;

class PostDraft extends DraftModel
{
    /**
     * Return categories from draft
     */
    public function categories()
    {
        return $this->morphToMany('App\Category', 'categorable');
    }
}
```

You must create polymorphic relation from your model that can have draft.

Usage with Spatie Media Livrary
-------------------------------

[](#usage-with-spatie-media-livrary)

**POST MODEL**

```
namespace App;

use Illuminate\Database\Eloquent\Model;
use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\InteractsWithMedia;
use Nekodev\Drafty\Traits\Draftable;
use Nekodev\Drafty\Interfaces\HasDraftable;
use App\Category;

class Post extends Model implements HasMedia, HasDraftable
{
    use Draftable;
    use InteractsWithMedia;

    public $fillable = [ 'title', 'content' ];

    /**
     * Get the post's draft.
     */
    public function draft()
    {
        return $this->morphOne('App\Drafts\PostDraft', 'draftable');
    }
}
```

**CUSTOM DRAFT MODEL**

```
namespace App\Drafts;

use Nekodev\Drafty\Models\Draft as DraftModel;
use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\InteractsWithMedia;

class PostDraft extends DraftModel implements HasMedia
{
    use InteractsWithMedia;
}
```

On apply `save` method from `Post` model, all media collection from Post model are remove and replace by `PostDraft` model collection.

Credit
------

[](#credit)

[![alt text](https://avatars3.githubusercontent.com/u/18350326?s=25&u=3389cb6f56e0c28522e2b5e6a614ae207339f495&v=4 "Logo Title Text 1")](https://avatars3.githubusercontent.com/u/18350326?s=25&u=3389cb6f56e0c28522e2b5e6a614ae207339f495&v=4)[@nekodesigner (NekoDev)](https://github.com/NekoDesigner) - Tahar CHIBANE | FullStack Developer

Enjoy !! 😃

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

2120d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/15170540?v=4)[nekodev](/maintainers/nekodev)[@Nekodev](https://github.com/Nekodev)

---

Top Contributors

[![NekoDesigner](https://avatars.githubusercontent.com/u/18350326?v=4)](https://github.com/NekoDesigner "NekoDesigner (6 commits)")

### Embed Badge

![Health badge](/badges/nekodev-drafty/health.svg)

```
[![Health](https://phpackages.com/badges/nekodev-drafty/health.svg)](https://phpackages.com/packages/nekodev-drafty)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
