Skip to content

Commit

Permalink
Customize a specific wizard base view
Browse files Browse the repository at this point in the history
  • Loading branch information
ycs77 committed Jun 17, 2019
1 parent 2f46bdc commit 168a689
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
8 changes: 6 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ Publish config:
php artisan vendor:publish --tag=wizard-config
```

The this package view is use [Bootstrap 4](https://getbootstrap.com/), but if you don't want to use, you can publish views and translations to custom it:
The this package view is use [Bootstrap 4](https://getbootstrap.com/), but if you don't want to use, you can publish views to custom it, or [Customize a specific wizard base view](#customize-a-specific-wizard-base-view):

```bash
php artisan vendor:publish --tag=wizard-resources
php artisan vendor:publish --tag=wizard-views
```

## Usage
Expand Down Expand Up @@ -186,6 +186,10 @@ protected $wizardOptions = [
];
```

### Customize a specific wizard base view

If you want to customize the wizard base view, you can copy the view to `resources/views/user`. (`user` is `wizardName` property value on wizard controller),

### Set step relationships model

Similarly, you can set the relationships model in `setModel` method of `Step`.
Expand Down
20 changes: 18 additions & 2 deletions src/Http/Controllers/WizardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public function create(Request $request, $step = null)
$formAction = $this->getActionMethod('create');
$postAction = $this->getActionMethod('store');

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

/**
Expand Down Expand Up @@ -189,7 +189,7 @@ public function done(Request $request)
$stepRepo = $this->wizard()->stepRepo();
$doneText = $this->doneText;

return view('wizard::done', compact('wizardData', 'stepRepo', 'doneText'));
return view($this->getViewPath('done'), compact('wizardData', 'stepRepo', 'doneText'));
}

/**
Expand Down Expand Up @@ -344,6 +344,22 @@ protected function getNextStepSlug()
return $this->wizard()->stepRepo()->nextSlug();
}

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

return "wizard::$view";
}

/**
* Save wizard data.
*
Expand Down
5 changes: 4 additions & 1 deletion src/WizardServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ public function boot()

$this->publishes([
__DIR__ . '/../resources/views' => resource_path('views/vendor/wizard'),
], 'wizard-views');

$this->publishes([
__DIR__ . '/../resources/lang' => resource_path('lang/vendor/wizard'),
], 'wizard-resources');
], 'wizard-languages');
}
}

0 comments on commit 168a689

Please sign in to comment.