PHP code example of digitalcloud / nova-resource-status

1. Go to this page and download the library: Download digitalcloud/nova-resource-status library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

digitalcloud / nova-resource-status example snippets




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

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



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

}
shell
php artisan vendor:publish --provider="DigitalCloud\NovaResourceStatus\ToolServiceProvider" --tag=migrations
shell
php artisan migrate
shell
php artisan vendor:publish --provider="DigitalCloud\NovaResourceStatus\ToolServiceProvider" --tag=config