Publishable
Enso provides a way to easily add a "published" state to your crud model, including some query scopes and a "publish at" date that allows you to publish an item at a set date in the future.
- Add a
publishedboolean to your model. - Add the
Yadda\Enso\Crud\Traits\IsPublishabletrait to your model. - Add the
Yadda\Enso\Crud\Traits\IsPublishableCrudtrait to your Crud config. - Add the
Yadda\Enso\Crud\Traits\PublishesItemstrait to your Crud Controller. - Add a checkbox to your Crud config.
Adding the checkbox
CheckboxField::make('published')
->setLabel('Ready to Publish?')
->setOptions([
'published' => '',
]),
Publishing in the Future
If you want to add a "publish at" date, add a datetime column to your model and then override the getPublishAtColumn method, e.g.:
/**
* Gets the name of the Publish At DateTime column on this publishable
*
* @return string|null
*/
public function getPublishAtColumn()
{
return 'publish_at';
}
Add a DateTimeField to your crud as follows:
DateTimeField::make('publish_at'),
Unpublishing in the Future
If you want to add an "unpublish at" date, add a datetime column to your model and then override the 'getUnpublishAtColumn' method, e.g.:
/**
* Gets the name of the Publish At DateTime column on this publishable
*
* @return string|null
*/
public function getUnpublishAtColumn()
{
return 'unpublish_at';
}
Add a DateTimeField to your crud as follows:
DateTimeField::make('unpublish_at'),
Viewing Unpublished items
If you want some users to be able to view your items, even when unpublished, you should override the 'getPublishViewOverridePermission' method, e.g."
/**
* Gets the name of the Publish At DateTime column on this publishable
*
* @return string|null
*/
public function getPublishViewOverridePermission()
{
return 'view-unpublished-pages';
}
Any users who have the permission you specify will NOT have unpublished items filtered out of published() queries for that datatype.