bmatovu/laravel-publishable
Larablocks Analysis
bmatovu/laravel-publishable works with Laravel 5 to 8 (latest release v1.1.0, Dec 10, 2020), all past end of life (the last on Jan 24, 2023): no more fixes, even for security.
Recommendation checks
Not advisedNot advised: no release or commit in over 2 years.
- No release or commit in over 2 years
- Supports only Laravel 5 to 8, past end of life since Jan 24, 2023
- No release in the last 12 months (last: Dec 10, 2020)
- 0 downloads a month (needs 10,000)
- 3 GitHub stars (needs 100)
State
Likely abandoned- No release or commit in over 2 years.
- Last stable release: Dec 10, 2020.
- No releases in the last 12 months.
- First released: Jun 23, 2020.
- 3 open issues on GitHub.
Data from Packagist and GitHub, checked by Larablocks on Dec 1, 2026.
| Install | |
|---|---|
composer require bmatovu/laravel-publishable |
|
| Latest Version: | v1.1.0 |
| PHP: | >=7.0.0 |
| Laravel: | 5 – 8 |
| License: | MIT |
| Last Updated: | Dec 13, 2020 |
| Links: | GitHub · Packagist |
Laravel Publishable.
This package contains a trait to make Eloquent models publishable. It enables the model to hold a published vs non-published state, which comes in handy for things like blog posts that can be drafts or final (published) posts.
It uses a published_at attribute to determine the model state ie, if the model published_at is null, the model isn't published.
Installation
Install via Composer package manager:
composer require bmatovu/laravel-publishable
Usage
Add the publsihed_at column to your database table.
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreatePostsTable extends Migration
{
public function up()
{
Schema::create('posts', function (Blueprint $table) {
// ...
$table->timestamp('published_at')->nullable();
});
}
}
To make a model publishable, use the Bmatovu\Publishable\Publishable trait on the model:
<?php
namespace App\Models;
use Bmatovu\Publishable\Publishable;
use Illuminate\Database\Eloquent\Model;
class Post extends Model
{
use Publishable;
}
{tip} The
Publishabletrait will automatically cast thepublished_atattribute to aDateTime/Carboninstance for you.
Now, when you call the publish method on the model, the published_at column will be set to the current date and time.
Querying Publishable Models
When querying a model that is publishable, the unpublished models will automatically be excluded from all query results.
$publishedPosts = Post::get();
$publishedPosts = Post::onlyPublished()->get();
However, you may force unpublished models to appear in a result set using the withDrafts method on the query:
$posts = Posts::withDrafts()->get();
You may also retrieve only unpublished models using the onlyDrafts method.
$drafts = Posts::onlyDrafts()->get();
To determine if a given model instance has been published, use the isPublished method:
if ($post->isPublished()) {
// ...
}
Publishing Models
You can save a model as published in your database like;
// Publishing a single model instance...
$post->publish();
// Publishing all related models...
$post->inLifeStyle()->publish();
Unpublishing Models
You can "un-published" a published model like;
$post->unpublish();
Related Packages
Automatically generate UUIDs for Eloquent models on creation and replication.
Just a simple sortable behaviour for your Laravel and Lumen eloquent model.
Version History
| Version | Released | PHP | Laravel | License |
|---|---|---|---|---|
| v1.1.0 | >=7.0.0 | ^5.5| | MIT | |
| v1.0.1 | >=7.0.0 | ^5.5| | MIT | |
| v1.0.0 | >=7.0.0 | ^5.5| | MIT |

