Skip to content

Commit

Permalink
Change with view data to wizard controller property
Browse files Browse the repository at this point in the history
  • Loading branch information
ycs77 committed Jun 20, 2019
1 parent fe61c32 commit eeb8094
Showing 1 changed file with 43 additions and 8 deletions.
51 changes: 43 additions & 8 deletions src/Http/Controllers/WizardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ class WizardController extends Controller
*/
protected $steps = [];

/**
* The data with to the wizard form view.
*
* @var array
*/
protected $withViewData = [];

/**
* The wizard done show texts.
*
Expand Down Expand Up @@ -108,18 +115,27 @@ public function create(Request $request, $step = null)
);
}

// Wizard step created event.
if ($redirectTo = $this->wizardStepCreated($request, $step)) {
return $redirectTo;
}

$wizard = $this->wizard();
$wizardTitle = $this->wizardTitle;
$stepRepo = $this->wizard()->stepRepo();
$formAction = $this->getActionMethod('create');
$postAction = $this->getActionMethod('store');

return view($this->getViewPath('base'), compact('wizard', 'wizardTitle', 'stepRepo', 'step', 'formAction', 'postAction'));
$this->pushWithViewData(compact(
'wizard',
'wizardTitle',
'step',
'stepRepo',
'formAction',
'postAction'
));

// Wizard step created event.
if ($redirectTo = $this->wizardStepCreated($request, $step)) {
return $redirectTo;
}

return view($this->getViewPath('base'), $this->withViewData);
}

/**
Expand Down Expand Up @@ -343,12 +359,31 @@ protected function getNextStepSlug()
}

/**
* Get view path
* Push the data with to the wizard form view.
*
* Example:
*
* $this->pushWithViewData(compact(
* 'data'
* ));
*
* @param array $data
* @return void
*/
protected function pushWithViewData(array $data)
{
foreach ($data as $key => $value) {
$this->withViewData[$key] = $value;
}
}

/**
* Get view path.
*
* @param string $view
* @return string
*/
public function getViewPath($view)
protected function getViewPath($view)
{
$viewPath = "wizards.{$this->wizardName}.$view";
if (view()->exists($viewPath)) {
Expand Down

0 comments on commit eeb8094

Please sign in to comment.