PHPackages                             optix/draftable - 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. [Database &amp; ORM](/categories/database)
4. /
5. optix/draftable

Abandoned → [optix/eloquent-draftable](/?search=optix%2Feloquent-draftable)Library[Database &amp; ORM](/categories/database)

optix/draftable
===============

Add draftable functionality to your eloquent models.

v2.1.0(5y ago)281.4k↓75%6[1 PRs](https://github.com/optixsolutions/eloquent-draftable/pulls)2MITPHPPHP ^7.3CI failing

Since Sep 3Pushed 3y ago1 watchersCompare

[ Source](https://github.com/optixsolutions/eloquent-draftable)[ Packagist](https://packagist.org/packages/optix/draftable)[ RSS](/packages/optix-draftable/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (6)Dependencies (2)Versions (8)Used By (2)

Eloquent Draftable
==================

[](#eloquent-draftable)

[![Packagist Version](https://camo.githubusercontent.com/af1268ddbbe97793ba07c661e792cb79297e209d51252c3176ec7700d07acbcb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6f707469782f656c6f7175656e742d647261667461626c65)](https://camo.githubusercontent.com/af1268ddbbe97793ba07c661e792cb79297e209d51252c3176ec7700d07acbcb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6f707469782f656c6f7175656e742d647261667461626c65)[![GitHub Workflow Status](https://camo.githubusercontent.com/268efc83ba49cd14736adc2d927143c992756b03346a34ea9eb3fe525adf0f8d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f6f70746978736f6c7574696f6e732f656c6f7175656e742d647261667461626c652f52756e2532307465737473)](https://camo.githubusercontent.com/268efc83ba49cd14736adc2d927143c992756b03346a34ea9eb3fe525adf0f8d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f6f70746978736f6c7574696f6e732f656c6f7175656e742d647261667461626c652f52756e2532307465737473)[![StyleCI](https://camo.githubusercontent.com/0067ecfd219d74106746e43726199e7a00bbee7054b4ea8ff95676820e06829a/68747470733a2f2f7374796c6563692e696f2f7265706f732f3133333438343730332f736869656c64)](https://camo.githubusercontent.com/0067ecfd219d74106746e43726199e7a00bbee7054b4ea8ff95676820e06829a/68747470733a2f2f7374796c6563692e696f2f7265706f732f3133333438343730332f736869656c64)

Add draftable functionality to your eloquent models.

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

[](#installation)

You can install this package via composer.

```
composer require optix/eloquent-draftable
```

Setup
-----

[](#setup)

1. Add a nullable timestamp `published_at` column to your model's database table.

    ```
    $table->timestamp('published_at')->nullable();
    ```
2. Include the `Optix\Draftable\Draftable` trait in your model.

    ```
    class Post extends Model
    {
        use Draftable;
    }
    ```

Usage
-----

[](#usage)

**Query scopes**

When the `Draftable` trait is included in a model, a global scope will be registered to automatically exclude draft records from query results. Therefore, in order to query draft records you must apply one of the local scopes outlined below.

```
// Only retrieve published records...
$onlyPublished = Post::all();

// Retrieve draft & published records...
$withDrafts = Post::withDrafts()->get();

// Only retrieve draft records...
$onlyDrafts = Post::onlyDrafts()->get();
```

**Publish a model**

```
$post = Post::withDrafts()->first();

// Publish without saving...
$post->setPublished(true);

// Publish and save...
$post->publish(); // or $post->publish(true);
```

When you attempt to publish a model that's already been published, the `published_at` timestamp will not be updated.

**Draft a model**

```
// Draft without saving...
$post->setPublished(false);

// Draft and save...
$post->draft(); // or $post->publish(false);
```

**Schedule a model to be published**

```
$publishDate = Carbon::now()->addWeek();
// $publishDate = '2020-01-01 00:00:00';
// $publishDate = '+1 week';

// Schedule without saving...
$post->setPublishedAt($publishDate);

// Schedule and save...
$post->publishAt($publishDate);
```

The methods outlined above both require a `$date` parameter of type `DateTimeInterface|string|null`.

**Get the published status of a model**

```
// Determine if the model is published...
$post->isPublished();

// Determine if the model is draft...
$post->isDraft();
```

License
-------

[](#license)

This package is licensed under the [MIT license](LICENSE.md).

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 90.9% 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 ~153 days

Recently: every ~102 days

Total

6

Last Release

2039d ago

Major Versions

v1.0.2 → v2.0.02020-03-09

PHP version history (2 changes)v2.0.0PHP ^7.2

v2.1.0PHP ^7.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/adbd093cb9569cb676e65db9cc4c59a9c7bf7d53753c7e1e574994270071c7ff?d=identicon)[optix](/maintainers/optix)

---

Top Contributors

[![Jack97](https://avatars.githubusercontent.com/u/19285044?v=4)](https://github.com/Jack97 "Jack97 (10 commits)")[![r1chm8](https://avatars.githubusercontent.com/u/25925437?v=4)](https://github.com/r1chm8 "r1chm8 (1 commits)")

---

Tags

drafteloquentlaravelpublishschedule

### Embed Badge

![Health badge](/badges/optix-draftable/health.svg)

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

###  Alternatives

[owen-it/laravel-auditing

Audit changes of your Eloquent models in Laravel

3.4k33.0M95](/packages/owen-it-laravel-auditing)[staudenmeir/eloquent-json-relations

Laravel Eloquent relationships with JSON keys

1.1k5.8M24](/packages/staudenmeir-eloquent-json-relations)[bavix/laravel-wallet

It's easy to work with a virtual wallet.

1.3k1.1M11](/packages/bavix-laravel-wallet)[dragon-code/migrate-db

Easy data transfer from one database to another

15717.4k](/packages/dragon-code-migrate-db)[gearbox-solutions/eloquent-filemaker

A package for getting FileMaker records as Eloquent models in Laravel

6454.8k2](/packages/gearbox-solutions-eloquent-filemaker)[cybercog/laravel-ownership

Laravel Ownership simplify management of Eloquent model's owner.

9126.6k3](/packages/cybercog-laravel-ownership)

PHPackages © 2026

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