PHP code example of james.rus52 / laravel-wizard

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

    

james.rus52 / laravel-wizard example snippets


   
    Route::get('/create/{step?}', [\App\Http\Controllers\CreationRequestsController::class, 'create'])
            ->name('requests.create');
        Route::post('/create/{step}', [\App\Http\Controllers\CreationRequestsController::class, 'store'])
            ->name('requests.store');
    

   
   class InformationStepWizard extends \jamesRUS52\Laravel\Step
   {
      public function process(Request $request)
      {
         $this->saveProgress($request);
      }

       public function getAuxData(): array
       {
           return [
               'owners' => 'Some extra data for view on this step',
           ];
       }

       public function rules(Request $request = null): array
       {
           return [
               'owner' => '

    class CreationRequestsController extends Controller
   {
   protected Wizard $wizard;
   
       public function __construct()
       {
           $this->wizard = new Wizard('Request wizard', [
               new InformationStepWizard('information', 'Information', 'requests.create.information-step-wizard'),
               new RequestTypeStepWizard('request-type', 'Request type', 'requests.create.request-type-step-wizard'),
               new ResourcesStepWizard('resources', 'Choose resources', 'requests.create.resources-step-wizard'),
               new ConfirmationStepWizard('confirmation', 'Confirmation', 'requests.create.confirmation-step-wizard'),
           ],
               'creation-request'
           );
       }
   
       public function create($step_slug = null)
       {
           try {
               if (is_null($step_slug)) {
                   $step = $this->wizard->firstOrLastProcessed();
               } else {
                   $step = $this->wizard->getBySlug($step_slug);
               }
           } catch (StepNotFoundException $e) {
               abort(404);
           }
   
           return view('requests.create.layout-wizard',
               array_merge([
                       'type' => 'creation',
                   ],
                   $step->getAuxData(),
               )
           );
       }
   
       public function store(Request $request, $step_slug = null)
       {
           try {
               $step = $this->wizard->getBySlug($step_slug);
           } catch (StepNotFoundException $e) {
               abort(404);
           }
   
           $this->validate($request, $step->rules($request));
           $step->process($request);
   
           if ($this->wizard->hasNext()) {
               return redirect()->route('requests.create.', [$this->wizard->nextStep(false)->slug]);
           }
   
           // Finaly Create Request
           $full_wizard_data = $this->wizard->data();
           $this->wizard->clearProgress();
   
           return redirect()->route('requests.index');
       }
   }
    

    <h4>{{$wizard->getTitle()}}</h4>
    <div class="container container-fluid mt-4 mb-5">
        <div class="row">
        @foreach($wizard->getSteps() as $step)
            <div class="col text-center">
                @if($step->index == $wizard->currentStep()->index)
                    <strong>{{ $step->label }}</strong>
                @elseif($wizard->currentStep()->index > $loop->index)
                    <a class="text-primary" href="{{ route('requests.create.'.$type, [$step->slug]) }}">{{ $step->label }}</a>
                @else
                    {{ $step->label }}
                @endif
            </div>
        @endforeach
        </div>
        <div class="progress m-2">
            <div class="progress-bar" role="progressbar" style="width: {{$wizard->completionPercent()}}%;" aria-valuenow="{{$wizard->completionPercent()}}" aria-valuemin="0" aria-valuemax="100">{{$wizard->completionPercent()}}%</div>
        </div>
    </div>


    <form action="{{ route('requests.store.'.$type, [$wizard->currentStep()->slug]) }}" method="POST" novalidate>
        @csrf

        <div class="container mt-5">
            <div class="row justify-content-center">
                <div class="col-12 col-lg-9">
                    @