PHP code example of loubal70 / livewire-wizard

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

    

loubal70 / livewire-wizard example snippets




namespace App\Http\Livewire;

use loubal70\LivewireWizard\WizardComponent;
use App\Models\User;

class UserWizard extends WizardComponent
{
    // My custom class property
    public $userId;
    
    /*
     * Will return App\Models\User instance or will create empty User (based on $userId parameter) 
     */
    public function model()
    {
        return User::findOrNew($this->userId);
    }
}

$wizardFormInstance->resetForm();

$wizardFormInstance->getCurrentStep();

$wizardFormInstance->setStep($step);

$wizardFormInstance->goToNextStep();

$wizardFormInstance->goToPrevStep();



namespace App\Steps;

use loubal70\LivewireWizard\Components\Step;
use Illuminate\Validation\Rule;

class General extends Step
{
    // Step view located at resources/views/steps/general.blade.php 
    protected string $view = 'steps.general';

    /*
     * Initialize step fields
     */
    public function mount()
    {
        $this->mergeState([
            'name'                  => $this->model->name,
            'email'                 => $this->model->email,
        ]);
    }
    
    /*
    * Step icon 
    */
    public function icon(): string
    {
        return 'check';
    }

    /*
     * When Wizard Form has submitted
     */
    public function save($state)
    {
        $user = $this->model;

        $user->name     = $state['name'];
        $user->email    = $state['email'];
        
        $user->save();
    }

    /*
     * Step Validation
     */
    public function validate()
    {
        return [
            [
                'state.name'     => ['

use loubal70\LivewireWizard\Components\Step;

class General extends Step
{
    public function onStepIn($name, $value)
    {
        // Something you want
    }

    public function onStepOut($name, $value)
    {
        // Something you want
    }

    public function updating($name, $value)
    {
        // Something you want
    }

    public function updatingState($name, $value)
    {
        // Something you want
    }
    
    public function updated($name, $value)
    {
        // Something you want
    }

    public function updatedState($name, $value)
    {
        // Something you want
    }
}



namespace App\Http\Livewire;

use App\Steps\General;
use loubal70\LivewireWizard\WizardComponent;

class UserWizard extends WizardComponent
{
    public array $steps = [
        General::class,
        // Other steps...
    ];
   
    ...
}
shell
php artisan vendor:publish --tag=livewire-wizard-views
js
module.exports = {
    presets: [
        **/*.blade.php",
        "./resources/**/*.js",
        "./resources/**/*.vue",

        "./vendor/loubal70/livewire-wizard/resources/views/*.blade.php",
        "./vendor/wireui/wireui/resources/**/*.blade.php",
        "./vendor/wireui/wireui/ts/**/*.ts",
        "./vendor/wireui/wireui/src/View/**/*.php"
    ],
    plugins: [