2017 © Pedro Peláez
 

library laravel-wizard

Wizard component for laravel5.

image

smajti1/laravel-wizard

Wizard component for laravel5.

  • Saturday, September 23, 2017
  • by smajti1
  • Repository
  • 2 Watchers
  • 10 Stars
  • 431 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 4 Forks
  • 0 Open issues
  • 4 Versions
  • 16 % Grown

The README.md

Laravel-wizard

simple laravel step-by-step wizard, (*1)

Version Laravel Version Php Version
1.1 5.* ^7.0
^1.4 6.* || 7.* || 8.* ^7.2

Install

$ composer require smajti1/laravel-wizard

Example/How

  1. add routes, (*2)

    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');
    
  2. create steps, (*3)

    add autoload field in composer.json file:, (*4)

    ...
    "autoload": {
       "psr-4": {
            ...
            "App\\Wizard\\Steps\\": "app/Steps"
        },
    ...

    regenerate autoloader, (*5)

    $ composer dump-autoload

    create step app/Steps/SetUserNameStep.php, (*6)

    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' => 'required|min:4|max:255',
            ];
        }
    }
    
  3. create controller, (*7)

    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()]);
    }
    
  4. add base view $wizard variable is now automatic sheared with view, (*8)



      @foreach($wizard->all() as $key => $_step)
    1. @if($step->index == $_step->index) {{ $_step::$label }} @elseif($step->index > $_step->index) {{ $_step::$label }} @else {{ $_step::$label }} @endif
    2. @endforeach
    {{ csrf_field() }} @include($step::$view, compact('step', 'errors')) @if ($wizard->hasPrev()) Back @else Back @endif Step {{ $step->number }}/{{ $wizard->limit() }} @if ($wizard->hasNext()) @else @endif

License

Laravel wizard is open-sourced software licensed under the MIT license, (*9)

The Versions

23/09 2017

dev-master

9999999-dev

Wizard component for laravel5.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Hubert Dziubiński

laravel wizard

23/09 2017

v1.1.1

1.1.1.0

Wizard component for laravel5.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Hubert Dziubiński

laravel wizard

21/09 2017

v1.1.0

1.1.0.0

Wizard component for laravel5.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Hubert Dziubiński

laravel wizard

13/11 2016

v1.0.0

1.0.0.0

Wizard component for laravel5.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Hubert Dziubiński

laravel wizard