This Laravel Nova field allows you to make drafts of your resources.
- Create Drafts
- Unpublish resources (disable them)
- Artisan Command to create Migration
Install the package in a Laravel Nova project via Composer:
composer require optimistdigital/nova-drafts
This field requires a few database changes - namely, the model requires three new columns Migrations can be created using the following Artisan command:
php artisan drafts:migration {table?}
if table name is not provided, a choice of all available tables is provided.
If your table has pre-existing Unique constraint: It's recommended to add 'published' field to the unique constraint. More information inside the migration file.
use OptimistDigital\NovaDrafts\DraftButton;
use OptimistDigital\NovaDrafts\PublishedField;
use OptimistDigital\NovaDrafts\UnpublishButton;
public function fields(Request $request)
{
return [
UnpublishButton::make('Unpublish'),
DraftButton::make('Draft'),
PublishedField::make('State', 'published'),
]
}
Inside your Model add the following snippet:
public function childDraft()
{
return $this->hasOne(YourModelName::class, 'draft_parent_id', 'id');
}
Inside your Index Query use that function, to filter out published pages that have drafts:
public static function indexQuery(NovaRequest $request, $query)
{
return $query->doesntHave('childDraft');
}
Possible option you can pass to the field using the option name as a function
Option | Type | Default | Description |
---|---|---|---|
draftsEnabled |
boolean | true | boolean whether drafts are enabled or not |
The translation file(s) can be published by using the following publish command:
php artisan vendor:publish --provider="OptimistDigital\NovaDrafts\FieldServiceProvider" --tag="translations"
You can add your translations to resources/lang/vendor/nova-drafts/
by creating a new translations file with the locale name (ie et.json
) and copying the JSON from the existing en.json
.
Nova Drafts is open-sourced software licensed under the MIT license