1. Go to this page and download the library: Download smajti1/laravel-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/ */
smajti1 / laravel-wizard example snippets
use App\Http\Controllers\UserWizardController;
Route::get('wizard/user/{step?}', [UserWizardController::class, 'wizard'])->name('wizard.user');
Route::post('wizard/user/{step}', [UserWizardController::class, 'wizardPost'])->name('wizard.user.post');
namespace App\Wizard\Steps;
class SetUserNameStep extends \Smajti1\Laravel\Step
{
public static $label = 'Set user name';
public static $slug = 'set-user-name';
public static $view = 'wizard.user.steps._set_user_name';
public function process(\Illuminate\Http\Request $request)
{
// for example, create user
...
// next if you want save one step progress to session use
$this->saveProgress($request);
}
public function rules(\Illuminate\Http\Request $request = null): array
{
return [
'username' => '
public $steps = [
'set-username-key' => SetUserNameStep::class,
SetPhoneStep::class,
...
];
protected $wizard;
public function __construct()
{
$this->wizard = new Wizard($this->steps, $sessionKeyName = 'user');
}
public function wizard($step = null)
{
try {
if (is_null($step)) {
$step = $this->wizard->firstOrLastProcessed();
} else {
$step = $this->wizard->getBySlug($step);
}
} catch (StepNotFoundException $e) {
abort(404);
}
return view('wizard.user.base', compact('step'));
}
public function wizardPost(Request $request, $step = null)
{
try {
$step = $this->wizard->getBySlug($step);
} catch (StepNotFoundException $e) {
abort(404);
}
$this->validate($request, $step->rules($request));
$step->process($request);
return redirect()->route('wizard.user', [$this->wizard->nextSlug()]);
}