0

Good morning, I want build a multistep form in Laravel and I discover a lot of tutorial on Youtube to make this but In my form, I use a Foreach because I build a exam system and I display Question and Response with foreach.

This is my Code :

<form method="POST" action="{{ route('stagiaire.session.test.store',['id'=>$eval->id]) }}">
                        @csrf
                        @foreach($questioncat as $category)
                            <div class="card mb-3">
                                <div class="card-header">{{ $category->nom }}</div>

                                <div class="card-body">
                                    @foreach($category->getQuestion as $question)
                                        <div class="card @if(!$loop->last)mb-3 @endif">
                                            <div class="card-header">{{ $question->question_text }}</div>

                                            <div class="card-body">
                                                <input type="hidden" name="questions[{{ $question->id }}]" value="">
                                                @foreach($question->reponse as $option)
                                                    <div class="form-check">
                                                        <input class="form-check-input" type="radio" name="questions[{{ $question->id }}]" id="option-{{ $option->id }}" value="{{ $option->id }}"@if(old("questions.$question->id") == $option->id) checked @endif>
                                                        <label class="form-check-label" for="option-{{ $option->id }}">
                                                            {{ $option->option_text }}
                                                        </label>
                                                    </div>
                                                @endforeach


                                                @if($errors->has("questions.$question->id"))
                                                    <span style="margin-top: .25rem; font-size: 80%; color: #e3342f;" role="alert">
                                                        <strong>{{ $errors->first("questions.$question->id") }}</strong>
                                                    </span>
                                                @endif
                                            </div>
                                        </div>
                                    @endforeach
                                </div>
                            </div>
                        @endforeach

                        <div class="form-group row mb-0">
                            <div class="col-md-6">
                                <button type="submit" class="btn btn-primary">
                                    Submit
                                </button>
                            </div>
                        </div>
                    </form>

So my question, is it possible to build a multistep form with foreach?

Thanks

I am at the thinking stage

Chrisdev
  • 39
  • 7

0 Answers0