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.

  1. Add a published boolean to your model.
  2. Add the Yadda\Enso\Crud\Traits\IsPublishable trait to your model.
  3. Add the Yadda\Enso\Crud\Traits\IsPublishableCrud trait to your Crud config.
  4. Add the Yadda\Enso\Crud\Traits\PublishesItems trait to your Crud Controller.
  5. 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.