PHP code example of idkwhoami / flux-wizards

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

    

idkwhoami / flux-wizards example snippets


use Idkwhoami\FluxWizards\Concretes\Step;
use Idkwhoami\FluxWizards\Concretes\Wizard;
use Idkwhoami\FluxWizards\Traits\HasWizard;
use Livewire\Component;

class MyWizard extends Component
{
    use HasWizard;

    public array $data = [];

    protected function createWizard(): Wizard
    {
        $step1 = Step::make('step1')->label('First Step');
        $step2 = Step::make('step2')->label('Second Step');

        $step1->children([$step2]);

        return Wizard::make('my-wizard')
            ->root($step1)
            ->directory('wizards.my-wizard');
    }

    protected function complete(array $data): void
    {
        // Process the collected data
        session()->flash('message', 'Wizard completed!');
    }
}



namespace App\Livewire;

use Idkwhoami\FluxWizards\Concretes\Step;
use Idkwhoami\FluxWizards\Concretes\Wizard;
use Idkwhoami\FluxWizards\Traits\HasWizard;
use Livewire\Component;

class UserRegistrationWizard extends Component
{
    use HasWizard;

    // Data that will be collected through the wizard
    public array $data = [
        'account' => [],
        'profile' => [],
        'billing' => [],
    ];

    /**
     * Create the wizard instance.
     *
     * @return Wizard
     */
    protected function createWizard(): Wizard
    {
        // Create the root step
        $accountStep = Step::make('account')
            ->label('Account Information')
            ->rules([
                'email' => '('billing') && ($data['account.plan'] ?? '') === 'free') {
                return false;
            }

            return true;
        });

        // Set up the step hierarchy
        $accountStep->children([
            $profileStep->children([
                $billingStep
            ])
        ]);

        // Create and return the wizard
        return Wizard::make('user-registration')
            ->root($accountStep)
            ->directory('wizards.user-registration'); // Directory where step views are stored
    }

    /**
     * Handle completion of the wizard.
     *
     * @param array $data
     * @return void
     */
    protected function complete(array $data): void
    {
        // Process the collected data
        // For example, create a user, set up billing, etc.

        // Redirect or show a success message
        session()->flash('message', 'Registration completed successfully!');
        $this->redirect('/dashboard');
    }
}
blade
@step('account')
    <!-- Content for the account step -->
@endstep

@step('profile')
    <!-- Content for the profile step -->
@endstep
bash
php artisan vendor:publish --provider="Idkwhoami\FluxWizards\FluxWizardsServiceProvider"
bash
php artisan vendor:publish --tag=flux-wizards-lang