1. Go to this page and download the library: Download brexis/laravel-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 Brexis\LaravelWorkflow\Traits\WorkflowTrait;
class BlogPost extends Model
{
use WorkflowTrait;
}
use App\BlogPost;
use Workflow;
$post = BlogPost::find(1);
$workflow = Workflow::get($post);
// if more than one workflow is defined for the BlogPost class
$workflow = Workflow::get($post, $workflowName);
$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
// Using the WorkflowTrait
$post->workflow_can('publish'); // True
$post->workflow_can('to_review'); // False
// Get the post transitions
foreach ($post->workflow_transitions() as $transition) {
echo $transition->getName();
}
// if more than one workflow is defined for the BlogPost class
foreach ($post->workflow_transitions($workflowName) as $transition) {
echo $transition->getName();
}
// Apply a transition
$post->workflow_apply('publish');
$post->save();