mathewparet / requires-publishing
Add record publishing unpublishing features to a model.
v1.0.0
2023-08-03 05:58 UTC
Requires
- php: ^8.0
- illuminate/contracts: ^10.0
- illuminate/database: ^8.0|^9.0|^10.0
- illuminate/support: ^10.0
This package is not auto-updated.
Last update: 2025-01-03 11:10:47 UTC
README
Provide the ability to models to be published.
Features
- Publish / Unpublish a model.
- Published models are not considered for any queries by default (adds a global scope).
Installation
composer require mathewparet/requires-publishing
Defining a field to hold publish status in migrations
// define a 'published_at' field of type dateTime and is nullable
$table->requiresPublishing();
or
// define a 'active_at' field of type dateTime and is nullable
$table->requiresPublishing('active_at');
Add the funtionality to your model
// ...
use mathewparet\RequiresPublishing\RequiresPublishing;
// ...
class User extends Authenticatable
{
// ...
use RequiresPublishing;
// ...
/**
* To use custom field name for publishing, use the below line. If the below line isn't
* defined, the field is assumed to be 'published_at'.
*/
const PUBLISHED_AT = 'active_at';
}
API referance
This package introduces the below methods:
Name | Availability | Description |
---|---|---|
requiresPublishing() | Blueprint | Macro to define a field that holds the publish state for the record. |
publish() | Model | Mark a model as published. |
publishQuetly() | Model | Mark a model as published without raising any events. |
unpublish() | Model, Builder | Mark a model as unpublished. |
unpublishQuetly() | Model | Mark a model as unpublished without raising any events. |
withUnpublished() | Model | Add unpublished records to the scope. |
withoutUnpublished() | Model | Remove unpublished records from scope. |
onlyUnpublished() | Model | Scope the query to only consider unpublished records. |
Events
suspending
suspneded
unsuspending
unsuspended