Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Livewire Wizard Laravel Package

spatie/laravel-livewire-wizard

Lightweight Livewire components for building multi-step wizards in Laravel. Define a wizard with an ordered list of step components, each with its own screen and Livewire logic, and guide users through checkout-style flows with ease.

View on GitHub
Deep Wiki
Context7

title: Setting initial state weight: 5

There are various ways to customize what your wizard should initially display.

Starting at a specific step

If you want to let your wizard display a specific step when it is first rendered, you can pass the step name to the show-step property of the wizard.

<livewire:checkout-wizard show-step="confirm-order" />

Setting initial state

To let the steps start with other values than the ones hardcoded in your steps, you can pass initial state via the initial-state property. The value given must be an array. The key of each item needs to be the name of a step, the value an array containing the state for that step. Here's an example:

[@php](https://github.com/php)
$initialState = [
    'delivery-address-step' => [
        // ...
        'zip' => '10000',
        'city' => 'Washington',
    ],
];

[@endphp](https://github.com/endphp)

<livewire:checkout-wizard show-step="confirm-order" :initial-state="$initialState" />

Instead of passing initial state via the initial-state property, you could let your WizardComponent implement initialState and let that function return the initial state.

In this example we'll pass the user id as a prop, and fetch the relevant details in the initialState function.

{{-- in your blade view --}}
<livewire:checkout-wizard show-step="confirm-order" :user-id="$userId",  />
namespace App\Components;

use Spatie\LivewireWizard\Components\WizardComponent;

class CheckoutWizardComponent extends WizardComponent
{
    public function mount(string $userId)
    {
        $this->userId = $userId;
    }
    
    public function initialState(): array
    {
        $user = User::findOrFail($this->userId);
        
        return [
            'delivery-address-step' => [
                'zip' => $user->zip,
                'city' => $user->city,
            ],       
        ];
    }
}
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport