Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Publishable Laravel Package

pawelmysior/laravel-publishable

View on GitHub
Deep Wiki
Context7

Publishable

Toggle the published state of your Eloquent models easily.

Installation

You can install the package via composer:

composer require pawelmysior/laravel-publishable

Versions

For details about which version of this package to use with your Laravel version please see the table below:

Laravel Version Package Version
<9.x 1.x
9.x 2.x
10.x 3.x
11.x 4.x
12.x 5.x

Preparation

To start you need to add a published_at nullable timestamp column to your table.

Put this in your table migration:

$table->timestamp('published_at')->nullable();

Now use the trait on the model

<?php
 
namespace App;
  
use Illuminate\Database\Eloquent\Model;
use PawelMysior\Publishable\Publishable;
 
class Post extends Model
{
    use Publishable;
}

Add Fillable Attribute

In Version 1.x, the published() function handles the update in a way where Laravel expects that the published_at field is fillable. As of Version 2.x, we not use fill functionality so the fillable attribute is no longer required.

Usage

You can now use those features:

// Get only published posts
Post::published()->get();
 
// Get only unpublished posts
Post::unpublished()->get();
 
// Check if the post is published
$post->isPublished();
 
// Check if the post is unpublished
$post->isUnpublished();
 
// Publish the post
$post->publish();
 
// Unpublish the post
$post->unpublish();

// Publish the post without firing model events
$post->publishQuietly();
 
// Unpublish the post without firing model events
$post->unpublishQuietly();

A post is considered published when the published_at is not null and in the past.

A post is considered unpublished when the published_at is null or in the future.

Security

If you discover any security-related issues, please email security@jaymeh.co.uk instead of using the issue tracker.

Contributing

Any contributions to this repository are welcomed. Please be aware that we are using conventional commits to assist in self documentation and reduce manual work involved with releases.

License

The MIT License (MIT). Please see License File for more information.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle