PHP code example of fazzinipierluigi / laravel-rails
1. Go to this page and download the library: Download fazzinipierluigi/laravel-rails 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/ */
$transition->can($instance); // State match + advance permission + execute_condition
$transition->can_show($instance); // State match + view permission + show_condition
$transition->can_exit($instance); // exit_condition only
$transition->canAdvance($user); // Advance permission only (no instance needed)
use Fazzinipierluigi\LaravelRails\Interfaces\ActionInterface;
class MyAction implements ActionInterface
{
public static string $display_name = 'My Action';
public static array $configuration_schema = [
['name' => 'message', 'type' => 'text', 'label' => 'Message', '
$instance->state; // Current State model
$instance->state_id; // Current State UUID
$instance->workflow; // Workflow model
$instance->entity; // The entity (Order, User, etc.)
$instance->variables; // Array of workflow variables
use Fazzinipierluigi\LaravelRails\Classes\VariableResolver;
$resolved = VariableResolver::resolve('Hello {{variables.name}}, total: {{variables.total}}', $instance, $entity);
$instance->getVariable('price'); // dot-notation get, returns null if missing
$instance->getVariable('price', 0); // with default
$instance->setVariable('status', 'active'); // dot-notation set + save
$instance->mergeVariables(['a' => 1, 'b' => 2]); // merge + save
$instance->hasVariable('price'); // bool
interface PermissionResolverInterface
{
public function check(mixed $user, array $permissions, string $operator = 'OR'): bool;
public function getDriverName(): string;
}
class MyResolver implements PermissionResolverInterface
{
public function check(mixed $user, array $permissions, string $operator = 'OR'): bool
{
// Your logic here
}
public function getDriverName(): string { return 'my-driver'; }
}
$transitions = $instance->availableTransitions();
// Returns Collection<Transition>, ordered by sort, filtered by can_show()
use Fazzinipierluigi\LaravelRails\Traits\IsWorkflowEntity;
class Order extends Model
{
use IsWorkflowEntity;
}
// Start the workflow for this entity
$order->startWorkflow('order-approval'); // workflow slug
// Get the current workflow instance
$instance = $order->getWorkflowInstance('order-approval');
// Advance the workflow
$redirectUrl = $order->progressWorkflow('order-approval');
// Fire a manual trigger
$order->fireManualTrigger('trigger-name-or-uuid');
class TestCase extends OrchestraTestCase
{
protected function getPackageProviders($app): array
{
return [LaravelRailsServiceProvider::class];
}
protected function getEnvironmentSetUp($app): void
{
$app['config']->set('database.default', 'testing');
$app['config']->set('database.connections.testing', [
'driver' => 'sqlite', 'database' => ':memory:',
]);
$app['config']->set('session.driver', 'array');
$app['config']->set('queue.default', 'sync');
}
protected function setUp(): void
{
parent::setUp();
Model::unguard(); // Allow ::create() calls
$this->artisan('migrate'); // Run all package migrations
// Create test entity tables (orders, users)
}
}
WorkflowFactory::twoState($slug) // Start → End
WorkflowFactory::threeState($slug) // Start → Middle → End
WorkflowFactory::withForm($slug) // Start -[form]-> Review → End
WorkflowFactory::withConditional($slug) // Start → Conditional → Branch A/B → End
WorkflowFactory::createOrder($attrs) // Create test Order entity
WorkflowFactory::addAction($model, $phase, $actionClass, $config)
$this->app->instance(PermissionResolverInterface::class, new VanillaGateResolver());
Gate::define('my-ability', fn($user) => true);
$this->actingAs($user);