Closed Vasiliy-Makogon closed 5 years ago
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:
The
getOptions
method is custom, can be changed at will.
app/Steps/User/NameStep.php
<?php
...
class NameStep extends Step
{
...
public function getOptions()
{
return [
'Taylor',
'Lucas',
];
}
}
resources/views/steps/user/name.blade.php
<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>
Use your data for example:
app/Steps/Docflow/FirstStep.php
<?php
...
class FirstStep extends Step
{
...
public function getDocumentTypes()
{
return DocflowHelper::documentTypeTreeToSelectArray(DocumentType::getLevel());
}
public function getDocumentStatuses()
{
return DocumentStatus::all()->where('active', '=', '1')->sortBy('id');
}
public function getUsers()
{
return User::all()->sortBy('last_name, first_name');
}
}
resources/views/steps/docflow/first.blade.php
{{ $step->getDocumentTypes() }}
{{ $step->getDocumentStatuses() }}
{{ $step->getUsers() }}
Happy coding 😄 !
Because each step is injected into the view of the step, so just add the method to return the data in the step class.
Great, thank you!
Hey. At the first step there is a form with a select list, you need to transfer data from the database to this list. In the standard action, we will do this:
How to do it for a step?