PHPackages                             lambdadigamma/laravel-publishable - 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. lambdadigamma/laravel-publishable

ActiveLibrary[Database &amp; ORM](/categories/database)

lambdadigamma/laravel-publishable
=================================

A Laravel Eloquent model trait for publishing and unpublishing

1.1.0(1y ago)3758↑445.5%2MITPHPPHP ^8.0|^8.1|^8.2|^8.3|^8.4CI passing

Since Mar 28Pushed 1y ago1 watchersCompare

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

READMEChangelogDependencies (6)Versions (10)Used By (2)

[![Laravel Publishable](https://camo.githubusercontent.com/4d53886a7e551a78a2be6f22cbe67ca3382154e8a355274de482f4d0d06b054e/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f4c61726176656c2532305075626c69736861626c652e706e673f7468656d653d6c69676874267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d6c616d626461646967616d6d612532466c61726176656c2d7075626c69736861626c65267061747465726e3d67726170685061706572267374796c653d7374796c655f32266465736372697074696f6e3d416e2b7075626c69736861626c652b74726169742b666f722b4c61726176656c2b456c6f7175656e742b6d6f64656c73266d643d312673686f7757617465726d61726b3d3026666f6e7453697a653d313530707826696d616765733d636c6f636b267769647468733d33303026686569676874733d333030)](https://camo.githubusercontent.com/4d53886a7e551a78a2be6f22cbe67ca3382154e8a355274de482f4d0d06b054e/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f4c61726176656c2532305075626c69736861626c652e706e673f7468656d653d6c69676874267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d6c616d626461646967616d6d612532466c61726176656c2d7075626c69736861626c65267061747465726e3d67726170685061706572267374796c653d7374796c655f32266465736372697074696f6e3d416e2b7075626c69736861626c652b74726169742b666f722b4c61726176656c2b456c6f7175656e742b6d6f64656c73266d643d312673686f7757617465726d61726b3d3026666f6e7453697a653d313530707826696d616765733d636c6f636b267769647468733d33303026686569676874733d333030)

[![Build Status](https://github.com/lambdadigamma/laravel-publishable/workflows/tests/badge.svg)](https://github.com/lambdadigamma/laravel-publishable/actions)[![Latest Stable Version](https://camo.githubusercontent.com/d3752e50bb3df93df5754555a06e19598ddda5a0240f93e3677149140ee94c3f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c616d626461646967616d6d612f6c61726176656c2d7075626c69736861626c65)](https://packagist.org/packages/lambdadigamma/laravel-publishable)[![License](https://camo.githubusercontent.com/87ec655efee27031bd85b3b3b15f27ee7cd6937396f2afa4527b5148bcfd1122/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6c616d626461646967616d6d612f6c61726176656c2d7075626c69736861626c65)](https://packagist.org/packages/lambdadigamma/laravel-publishable)

A simple package for making Laravel Eloquent models 'publishable'. Not published models are excluded from queries by default but can be queried via extra scope.

This package allows easy publishing and unpublishing of models by combining scopes and macros.

How does it work?
-----------------

[](#how-does-it-work)

The package provides a trait `Publishable` for your Eloquent model. Your database schema has to have a `published_at` datetime column so that the trait can read and write it. By reading this column the package can determine which models already have been published and provide the requested models.

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

[](#installation)

You can install the package via composer:

```
composer require lambdadigamma/laravel-publishable
```

Usage
-----

[](#usage)

#### Migrations

[](#migrations)

The `Publishable` trait works similarly to Laravel's `SoftDeletes` trait. This package provides a macro for Laravel's Migration Builder. Just use the `publishedAt` macro in your migration to get started:

```
Schema::create('posts', function (Blueprint $table) {
    $table->id();
    $table->string('title');
    $table->text('text');
    $table->timestamps();
    $table->publishedAt(); // Macro provided by the package
});
```

#### Eloquent Model Trait

[](#eloquent-model-trait)

After providing a `published_at` timestamp on your model, you can use the `Publishable` trait on your Eloquent model:

```
namespace App\Models;

use \Illuminate\Database\Eloquent\Model;
use \LaravelPublishable\Publishable;

class Post extends Model {
    use Publishable;
    ...
}
```

#### Extensions

[](#extensions)

The extensions shipped with this trait include; `publish`, `unpublish`, `withNotPublished`, `withoutPublished`, `onlyPublished` and can be used accordingly:

```
$post = Post::first();
$post->publish();
$post->publishAt(now()->addHour(1));
$post->scheduleFor(new Carbon('2021-04-01 10:00:00'));
$post->unpublish();

$postsWithNotPublished = Post::query()->withNotPublished();
$onlyNotPublishedPosts = Post::query()->onlyNotPublished();
```

When not specifing any additional scopes, all not published models are excluded from the query by default (`withoutNotPublished`) to prevent leaks of not published data.

### Testing

[](#testing)

`composer test`

### Changelog

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

### Security

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Lennart Fischer](https://github.com/lambdadigamma)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance45

Moderate activity, may be stable

Popularity19

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity75

Established project with proven stability

 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 ~179 days

Recently: every ~260 days

Total

9

Last Release

433d ago

Major Versions

0.0.3 → 1.0.02021-07-17

PHP version history (4 changes)0.0.1PHP ^7.3|^8.0

1.0.3PHP ^8.0|^8.1|^8.2

1.0.4PHP ^8.0|^8.1|^8.2|^8.3

1.1.0PHP ^8.0|^8.1|^8.2|^8.3|^8.4

### Community

Maintainers

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

---

Top Contributors

[![LambdaDigamma](https://avatars.githubusercontent.com/u/19361610?v=4)](https://github.com/LambdaDigamma "LambdaDigamma (13 commits)")

---

Tags

eloquentlaravelphplaravelcmspublishmodelsscopeunpublishlaravel-publishable

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/lambdadigamma-laravel-publishable/health.svg)

```
[![Health](https://phpackages.com/badges/lambdadigamma-laravel-publishable/health.svg)](https://phpackages.com/packages/lambdadigamma-laravel-publishable)
```

###  Alternatives

[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.8M26](/packages/tucker-eric-eloquentfilter)[watson/validating

Eloquent model validating trait.

9723.3M47](/packages/watson-validating)[yajra/laravel-oci8

Oracle DB driver for Laravel via OCI8

8703.0M17](/packages/yajra-laravel-oci8)[cybercog/laravel-love

Make Laravel Eloquent models reactable with any type of emotions in a minutes!

1.2k302.7k1](/packages/cybercog-laravel-love)[cviebrock/eloquent-taggable

Easy ability to tag your Eloquent models in Laravel.

567694.8k3](/packages/cviebrock-eloquent-taggable)[clickbar/laravel-magellan

This package provides functionality for working with the postgis extension in Laravel.

423715.4k1](/packages/clickbar-laravel-magellan)

PHPackages © 2026

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