/** * Handle an incoming request * * @param \Illuminate\Http\Request $request * @param Closure $next * @param string|null $guard * * @return mixed */ public function handle($request, Closure $next, $guard = null) { // Send a forbidden status if wizard should not be triggered if (TriggerHelper::hasWizardCompleted()) { return $this->forbiddenResponse(); } // Get the current step from the route slug $currentStepSlug = $request->route()->getParameter('slug', ''); \InstallWizard::initialize($currentStepSlug); // Share common data with our views view()->share('currentStep', \InstallWizard::currentStep()); view()->share('allSteps', \InstallWizard::steps()); // Proceed as usual return $next($request); }
/** * Apply current step and move on to next step * * @param Request $request * * @return Response */ protected function nextStep(Request $request) { // Apply the current step. If success, we can redirect to next one $currentStep = \InstallWizard::currentStep(); if (!$currentStep->apply($request->all())) { return view()->make('install_wizard::steps.default', ['errors' => $currentStep->getMessageBag()]); } // If we have a next step, go for it. Else we redirect to somewhere else try { $nextStep = \InstallWizard::nextStep(); return redirect()->route('install_wizard.show', ['slug' => $nextStep->getSlug()]); } catch (StepNotFoundException $e) { $finalRouteName = config('install_wizard.routing.success_route' . ''); if (!empty($finalRouteName)) { return redirect()->route($finalRouteName); } $finalRouteUrl = config('install_wizard.routing.success_url', ''); if (!empty($finalRouteUrl)) { return redirect()->to($finalRouteUrl); } return redirect('/'); } }