Download the PHP package bmatovu/laravel-publishable without Composer
On this page you can find all versions of the php package bmatovu/laravel-publishable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download bmatovu/laravel-publishable
More information about bmatovu/laravel-publishable
Files in bmatovu/laravel-publishable
Package laravel-publishable
Short Description Laravel publisable.
License MIT
Homepage https://github.com/mtvbrianking/laravel-publishable
Informations about the package laravel-publishable
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:
Usage
Add the publsihed_at
column to your database table.
To make a model publishable, use the Bmatovu\Publishable\Publishable
trait on the model:
{tip} The
Publishable
trait will automatically cast thepublished_at
attribute to aDateTime
/Carbon
instance 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.
However, you may force unpublished models to appear in a result set using the withDrafts
method on the query:
You may also retrieve only unpublished models using the onlyDrafts
method.
To determine if a given model instance has been published, use the isPublished
method:
Publishing Models
You can save a model as published in your database like;
Unpublishing Models
You can "un-published" a published model like;