PHP code example of invelity / laravel-headless-wizard

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

    

invelity / laravel-headless-wizard example snippets


use App\Wizards\OrderWizard;

public function store(Request $request, OrderWizard $wizard, string $step)
{
    $wizard->process($step, $request);   // validated by the step's form request

    return to_route('order.step', $wizard->current()->id());
}

namespace App\Wizards;

use App\Wizards\Steps\CalculatorStep;
use App\Wizards\Steps\ConfirmationStep;
use App\Wizards\Steps\PersonalDataStep;
use Invelity\WizardPackage\Wizard;

class OrderWizard extends Wizard
{
    protected array $steps = [
        CalculatorStep::class,
        PersonalDataStep::class,
        ConfirmationStep::class,
    ];
}

namespace App\Wizards\Steps;

use App\Http\Requests\Wizards\CalculatorRequest;
use App\Services\PriceCalculator;
use Invelity\WizardPackage\Step;

class CalculatorStep extends Step
{
    protected ?string $formRequest = CalculatorRequest::class;

    public function handle(array $data, PriceCalculator $prices): array
    {
        return [...$data, 'price' => $prices->quote($data['weight'])];
    }
}

Route::get('/order/{step}', [OrderController::class, 'show'])
    ->middleware('wizard.step:'.OrderWizard::class)   // redirects to the step the visitor should be on
    ->name('order.step');

Route::post('/order/{step}', [OrderController::class, 'store']);

Route::middleware('web')->group(function () {
    Route::wizard('order', OrderWizard::class);
});
bash
php artisan vendor:publish --tag=wizard-migrations
php artisan migrate
bash
php artisan wizard:make OrderWizard
php artisan wizard:make-step CalculatorStep --wizard=OrderWizard
php artisan wizard:make-step PersonalDataStep --wizard=OrderWizard
php artisan wizard:make-step ConfirmationStep --wizard=OrderWizard --display