Skip to content

Latest commit

 

History

History
44 lines (34 loc) · 1.15 KB

File metadata and controls

44 lines (34 loc) · 1.15 KB

Automatic Next States

StateFlow automatically discovers which states are reachable from the current state, eliminating the need for manual state selection in controllers.

Basic Usage

// Get available transitions from current state
$order->getNextStates();
// Returns: [Processing::class, Cancelled::class]

// Check if any transitions are available
$order->hasNextStates();
// Returns: true

// Check specific transition
$order->canTransitionTo(Processing::class);
// Returns: true

In Controllers

public function show(Order $order)
{
    return Inertia::render('orders/show', [
        'order' => $order,
        'nextStates' => collect($order->getNextStates())->map(fn ($class) => [
            'name' => $class::name(),
            'title' => $class::title(),
            'color' => $class::color(),
        ]),
    ]);
}

Benefits

  • No need to manually track which transitions are valid
  • Controllers stay simple and maintainable
  • Views can dynamically render transition buttons
  • Business logic stays in state configuration

📦 See it in action: laravel-stateflow-demo