1. Go to this page and download the library: Download j0hnys/trident-workflow 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/ */
namespace App;
use Illuminate\Database\Eloquent\Model;
use J0hnys\TridentWorkflow\Traits\WorkflowTrait;
class BlogPost extends Model
{
use WorkflowTrait;
}
use App\BlogPost;
use J0hnys\TridentWorkflow\WorkflowRegistry;
$workflow_name = 'straight';
$configuration = config('workflow')[$workflow_name];
$workflow_configuration = app()->make('J0hnys\TridentWorkflow\PackageProviders\Configuration');
$workflow_configuration->setWorkflow($workflow_name, $configuration);
$workflow_registry = new WorkflowRegistry($workflow_name);
$post = BlogPost::find(1);
$workflow = $workflow_registry->get($post);
$workflow->can($post, 'publish'); // False
$workflow->can($post, 'to_review'); // True
$transitions = $workflow->getEnabledTransitions($post);
// Apply a transition
$workflow->apply($post, 'to_review');
$post->save(); // Don't forget to persist the state