PHP code example of nowi5 / laravel-workflow

1. Go to this page and download the library: Download nowi5/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/ */

    

nowi5 / laravel-workflow example snippets


namespace  App\Workflow;

use App\Jobs\WorkflowStepJob;
use Workflow\Workflow;

class ExampleWorkflow extends Workflow {

    public $name = "TestWorkflow";
    public $version = "1.0.0";

    public function execute(){
        // Adding steps to the workflow
        $this->addStep("step1", WorkflowStepJob::class, ["param1" => "some value"]);

        // Setting the logic for the workflow
        $this->addLogic("step1", "step2");
    }
}

$workflow = new ExampleWorkflow();
$workflow->start("Hello Test");
$workflowjson = $workflow->getJson();
return response("<pre><code>".$workflowjson."</code></pre>", 200);

namespace App\Jobs;

use Workflow\Jobs\WorkflowJob;

class WorkflowStepJob extends WorkflowJob {

    public $name = "Example Step Name"; // Keep this unique
    public $version = "1.0.0";

    public function execute() {
        $content = "Hello Custom Workflow, " . now() . "\n";
        return ['content' => $content];
    }
}

$this->addStep("step2", WorkflowStepJob::class, ["param1" => "%step1.randomNumber%"]);

$this->addLogic("step3", null, [
["evaluate" => "%step2.outputParameterName%", "comparison" => "<50", "next" => "step5"],
["evaluate" => "%step2.outputParameterName%", "comparison" => ">=50", "next" => "step4"]
]);

   php artisan vendor:publish --provider="Workflow\WorkflowServiceProvider"
   

   php artisan migrate