optimistdigital/nova-drafts 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

optimistdigital/nova-drafts

最新稳定版本:1.1.8

Composer 安装命令:

composer require optimistdigital/nova-drafts

包简介

A Laravel Nova field that allows you to make drafts of your current resources.

README 文档

README

Latest Version on Packagist Total Downloads

This Laravel Nova field allows you to make drafts of your resources.

Features

  • Create Drafts
  • Unpublish resources (disable them)
  • Artisan Command to create Migration

Screenshots

Detail View

Form View

Index View

Installation

Install the package in a Laravel Nova project via Composer:

composer require optimistdigital/nova-drafts

Usage

Preparing the models and database

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.

Defining the field

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'),
    ]
}

Index Filtering (IndexQuery)

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');
}

Options

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

Localization and text customization

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.

Credits

License

Nova Drafts is open-sourced software licensed under the MIT license

统计信息

  • 总下载量: 45.29k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 29
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 28
  • Watchers: 3
  • Forks: 7
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-01-09