PHP code example of mrnewport / laravel-flow

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

    

mrnewport / laravel-flow example snippets


return [
    'morph_key_type' => 'int', // int (default), uuid, or ulid
    'user_model' => App\Models\User::class,
    'rejection_actions' => ['reject', 'cancel'],
];

use MrNewport\LaravelFlow\Models\FlowStep;
use MrNewport\LaravelFlow\Models\FlowTransition;

FlowStep::updateOrCreate(
    ['id' => 'proposal.review.v1'],
    ['name' => 'Review proposal'],
);

foreach (['approve', 'reject'] as $action) {
    FlowTransition::firstOrCreate([
        'step_id' => 'proposal.review.v1',
        'action' => $action,
        'next_step_id' => 'END',
    ]);
}

use MrNewport\LaravelFlow\FlowManager;

// Run within your application's authorized transaction.
$instance = FlowManager::startFlow('proposal.review.v1', $proposal);
$step = $instance->steps()->whereNull('finished_at')->sole();
$nextSteps = FlowManager::actionStep($step, 'approve');

use Illuminate\Database\Eloquent\Model;
use MrNewport\LaravelFlow\Traits\Flowable;

class Proposal extends Model
{
    use Flowable;
}

$proposal->startFlow('proposal.review.v1');
$step = $proposal->currentFlowStep();
$proposal->flowAction('approve');

$changed = FlowManager::reassignStep($step, $currentUser, [9, 10]);
sh
php artisan vendor:publish --provider='MrNewport\LaravelFlow\Providers\FlowServiceProvider' --tag=flow-config