digitalcloud/nova-resource-status

Laravel Nova 资源状态。

v1.4 2019-02-25 12:34 UTC

This package is auto-updated.

Last update: 2024-09-26 01:46:41 UTC


README

这是一个Laravel Nova包,允许您跟踪Nova资源的状态。

安装

您可以通过composer安装此包。

composer require digitalcloud/nova-resource-status

您必须发布迁移文件。

php artisan vendor:publish --provider="DigitalCloud\NovaResourceStatus\ToolServiceProvider" --tag=migrations

然后,迁移数据库表。

php artisan migrate

可选地,您可以发布配置文件。

php artisan vendor:publish --provider="DigitalCloud\NovaResourceStatus\ToolServiceProvider" --tag=config

这是将要发布到config/nova-resource-status.php的文件内容。

<?php

return [
    /*
     * The class name of the status model that holds all statuses.
     * The model must be or extend `DigitalCloud\NovaResourceStatus\Models\Status`.
     */
    'status_model' => DigitalCloud\NovaResourceStatus\Models\Status::class,

    /*
     * The default name of the status attribute if not declared in model.
     */
    'status-field' => 'status'
];

用法

您必须将HasStatus特性添加到资源模型中。

use DigitalCloud\NovaResourceStatus\HasStatus;

class YourEloquentModel extends Model
{
    use HasStatus;
    
    // use this function to indicate the status column in this model.
    // If this function not existed, then the value of `status-field`
    // form config file will be considered.
    public function statusField() {
        return 'yourStatusColumn';
    }
}

这将每次状态属性更改时添加数据库记录。

要显示所有状态日志,请在您的nova资源中添加Statuses字段。

<?php

namespace App\Nova;

use DigitalCloud\NovaResourceStatus\Fields\Statuses;
use Illuminate\Http\Request;

class YourResource extends Resource {
    
    // ...
    
    public static $model = 'YourEloquentModel'; // model must use `HasStatus` trait`
    
    public function fields(Request $request)
    {
        return [
            // ...
            // This will appear in the resource detail view.
            Statuses::make(),
            // ...
        ];
    }
    
    // ...

}

然后,在资源详情页面,您可以看到资源状态的历史记录。

图片

status