CRUD Traits

There are traits to help build up common functionality on your Cruds and Controllers

PublishesItems

Usage

Add this trait to your Crud controllers. It will provide functionality to work with Publish and Unpublish bulk actions.

You will then need to add routes for this functionality. The Route names should be based off of the route setting that you will have set in the Crud, with publish and unpublish as suffixes. If you had configured your Crud with ->route('admin.pages'), you would set them up as:

Route::post('admin/case-studies/publish', 'Admin\CaseStudyController@publish')->name('admin.case-studies.publish');
Route::post('admin/case-studies/unpublish', 'Admin\CaseStudyController@unpublish')->name('admin.case-studies.unpublish');

Optional / Extension

You may with to limit publishing of items to happen only when specific criteria are met. You can add a public canPublish() method to the Model that the Controller deals with. This should return a boolean value which defines whether the current state of the model is a valid state to publish.

You can also add a public $publish_criteria to the Model. This should be a string that describes what is required to publish that model. This message will be returned in if publishing fails.

Note: Publishing items is currently an all-or-nothing process. If you select multiple items and one of them fails, none of the selected items will be published. As such, it would be good to create a boolean column for the index that shows whether or not the item can be published.


IsPublishableCrud

Usage

Add this trait to your Crud that handles a Publishable Model. It will provide functionality to quickly set up Publishing-based bulk actions and filters.

You can then quickly add a Filter with:

$this->setItemFilters([
    'published' => $this->getPublishingFilter(),
]);

and Bulk actions with:

$this->setBulkActions([
    "actions" => $this->getPublishingBulkActions(),
]);

Optional / Extension

If you want to change the options available in the filter (for example, you don't care about items with a publish_at date for the filters), you should override getPublishedOptions and filterPublishedState to update it's functionality.