https://github.com/jaymeh/laravel-publishable
Toggle the published state of your Eloquent models easily
https://github.com/jaymeh/laravel-publishable
eloquent laravel publishable publishing trait
Last synced: 5 months ago
JSON representation
Toggle the published state of your Eloquent models easily
- Host: GitHub
- URL: https://github.com/jaymeh/laravel-publishable
- Owner: jaymeh
- License: mit
- Created: 2017-07-30T08:28:42.000Z (almost 9 years ago)
- Default Branch: 5.x
- Last Pushed: 2025-03-31T14:24:00.000Z (about 1 year ago)
- Last Synced: 2025-10-14T11:46:45.330Z (8 months ago)
- Topics: eloquent, laravel, publishable, publishing, trait
- Language: PHP
- Homepage:
- Size: 85.9 KB
- Stars: 22
- Watchers: 1
- Forks: 11
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Publishable
Toggle the published state of your Eloquent models easily.
## Installation
You can install the package via composer:
```bash
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:
```php
$table->timestamp('published_at')->nullable();
```
Now use the trait on the model
```php
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](https://www.conventionalcommits.org/en/v1.0.0/#summary) to assist in self documentation and reduce manual work involved with releases.
## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.