digitalcloud/nova-resource-status

A Laravel Nova Resource Status.

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

This package is auto-updated.

Last update: 2024-11-26 02:16:37 UTC


README

A laravel Nova package which allows you to track the status of your Nova resource.

Installation

You can install the package via composer:

composer require digitalcloud/nova-resource-status

You must publish the migrations file:

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

Then, migrate the database table:

php artisan migrate

Optionally, you can publish the config file:

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

This is the contents of the file which will be published at 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'
];

Usage

You must add HasStatus trait to the resource model.

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

This will add database record each time the status attribute changes.

To show all status log, add the Statuses field in your nova resource:

<?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(),
            // ...
        ];
    }
    
    // ...

}

Then, in resource detail page, you can see the history of your resource status.

Images

status