Wizard with steps from relationship

It's possible create steps in wizard from relationship? Like: Model Survey hasMany Categories Categories hasMany Answers In SurveyResource foreach category create step And in each step create repeater or somethin with answers
3 Replies
LeandroFerreira
I think it's possible. You can use a repeater->relationship() to hasMany items.
AlexAnder
AlexAnderOP2y ago
The Idea:
// SurveyResource
public static function form(Form $form): Form
{
return $form
->schema(
Wizard::make(
function (Survey $survey) {
$steps = [];
// Survey HasMany Categories
foreach ($survey->categories as $category) {
$steps[] = Wizard\Step::make($category->name)
->schema(
function (Category $category) {
$questions = [];
// Category HasMany Questions
foreach ($category->questions as $question) {
$questions[] = Forms\Components\TextInput::make($question->name);
// Question HasMany Answers
foreach ($question->answers as $answer) {
$questions[] = Forms\Components\TextInput::make($answer->name);
}
}
return $questions;
}
);
}
return $steps;
}
),
);
}
// SurveyResource
public static function form(Form $form): Form
{
return $form
->schema(
Wizard::make(
function (Survey $survey) {
$steps = [];
// Survey HasMany Categories
foreach ($survey->categories as $category) {
$steps[] = Wizard\Step::make($category->name)
->schema(
function (Category $category) {
$questions = [];
// Category HasMany Questions
foreach ($category->questions as $question) {
$questions[] = Forms\Components\TextInput::make($question->name);
// Question HasMany Answers
foreach ($question->answers as $answer) {
$questions[] = Forms\Components\TextInput::make($answer->name);
}
}
return $questions;
}
);
}
return $steps;
}
),
);
}
Is it possible somehow..
toeknee
toeknee2y ago
Should be possible with a closure on steps(function($record) { $steps = []; foeach($record->categories as $category} ) and so on
Want results from more Discord servers?
Add your server