Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
ycs77 committed Nov 6, 2019
1 parent c536f68 commit 875ce50
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ A web setup wizard for Laravel application.
- [Step](#step)
- [Get cache data](#get-cache-data)
- [Step repository](#step-repository)
- [Passing data to views](#passing-data-to-views)
- [Save data on other step](#save-data-on-other-step)
- [Set relationships model](#set-relationships-model)
- [Common Problems](#common-problems)
Expand Down Expand Up @@ -298,6 +299,51 @@ $nextStep = $step->getRepo()->next();

Step repository all can use method detailed reference: https://github.com/ycs77/laravel-wizard/blob/master/src/StepRepository.php

### Passing data to views

Because each step is injected into the view of the step, so just add the method to return the data in the step class. For example, pass the data of the select options to view:

*app/Steps/User/NameStep.php*
```php
<?php

...

class NameStep extends Step
{
...

public function getOptions()
{
return [
'Taylor',
'Lucas',
];
}
}

```

*resources/views/steps/user/name.blade.php*
```blade
<div class="form-group">
<label for="name">Select name</label>
<select id="name" name="name" class="form-control{{ $errors->has('name') ? ' is-invalid' : '' }}">
<option value="">Select...</option>
@foreach ($step->getOptions() as $option)
<option value="{{ $option }}" @if (old('name') ?? $step->data('name') === $option) @endif>{{ $option }}</option>
@endforeach
</select>
@if ($errors->has('name'))
<span class="invalid-feedback">{{ $errors->first('name') }}</span>
@endif
</div>
```

The `getOptions` method is custom, can be changed at will.

### Save data on other step

Suppose there are now two Steps `NameStep` and `EmailStep`.
Expand Down

0 comments on commit 875ce50

Please sign in to comment.