ympact/laravel-livewire-wizard
Installation
composer require ympact/laravel-livewire-wizard
Publish the config (if needed):
php artisan vendor:publish --provider="Ympact\LivewireWizard\LivewireWizardServiceProvider"
Basic Usage
Create a Livewire component extending Wizard:
use Ympact\LivewireWizard\Wizard;
class MultiStepForm extends Wizard
{
public function steps(): array
{
return [
'step1' => 'Step 1',
'step2' => 'Step 2',
'step3' => 'Step 3',
];
}
}
First Use Case Render the wizard in a Blade view:
<livewire:multi-step-form />
Define step content in renderStep():
public function renderStep($step)
{
return match($step) {
'step1' => view('steps.step1'),
'step2' => view('steps.step2'),
'step3' => view('steps.step3'),
};
}
Step Validation
Override validateStep() to enforce rules per step:
public function validateStep($step)
{
return match($step) {
'step1' => $this->validate(['name' => 'required']),
'step2' => $this->validate(['email' => 'required|email']),
default => true,
};
}
Dynamic Step Control
Use canGoNext()/canGoPrevious() to disable steps:
public function canGoNext($step)
{
return $step === 'step3' || $this->isStepValid($step);
}
Step Visibility Hide/show steps dynamically:
public function isStepVisible($step)
{
return $step !== 'step2' || $this->user->isPremium();
}
Form Submission
Use submit() to handle final submission:
public function submit()
{
$this->validate();
// Save data
$this->dispatch('wizard-submitted');
}
Progress Tracking
Access current step via $this->currentStep.
Custom Styling Extend the default Blade template or use Tailwind/Alpine for UI.
Validation Timing
validateStep() runs before rendering the step. Ensure rules match the step’s form fields.validate() in submit() for final validation.State Persistence
$this->currentStep manually.Step Naming
'step1' not 1). Use kebab-case for readability.Log Current Step
Add to mount():
\Log::debug('Current step:', [$this->currentStep]);
Check Validation Errors
Use $errors->all() in Blade to debug step-specific errors.
Custom Transitions
Override nextStep()/previousStep() for custom logic:
public function nextStep()
{
if ($this->currentStep === 'step2') {
$this->dispatch('confirm-before-proceed');
}
parent::nextStep();
}
Step Metadata
Attach data to steps via steps() array:
return [
'step1' => [
'title' => 'Personal Info',
'icon' => 'user',
],
];
Livewire Events
Listen for step-changed or wizard-submitted in Blade:
@script
Livewire.on('step-changed', step => {
console.log('Moved to step:', step);
});
@endscript
Default Views
The package lacks built-in views. Use the renderStep() method or create custom templates in resources/views/livewire/.
Livewire 4 Support Not yet implemented (check roadmap). Use at your own risk if upgrading.
How can I help you explore Laravel packages today?