Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

BrownieCoffee's avatar

get value multiple radio

Hi there,

I'm trying to build a quiz and there are 5 questions. Each question has 3 choices and 1 choice is correct. 1 selection is possible.

I'm trying to get the selected choices but my request()->all(); return empty array ....

Can you help me please?

Thank you

my html

     <div class="quiz-box__questions-list">
                @foreach($quiz->questions as $key => $question)

                <div class="quiz-box__question-box">
                    <span class="quiz-box__question-number">Question {{$question->question_identifier .' / '. $quiz->questions->count() }}</span>
                    <p class="quiz-box__question">{{$question->question}}</p>
                    @if(!empty($question->illustration))
                    <figure>
                        <img class="quiz-box__question-illustration" src="{{$question->illustration}}" alt="">
                    </figure>
                    @endif
                    <div class="quiz-box__choices-list">

                        @php
                        $choices = App\Models\Choice::where('question_identifier', $question->question_identifier)->where('quiz_id', $quiz->id)->get();
                        @endphp

                        @foreach($choices->shuffle()->all() as $choice)

                        <label class="quiz-box__choice uk-card uk-card-default">
                            <input class="quiz-box__radio" type="radio" name="question_{{$question->question_identifier}}_choice" value="{{$choice->id}}">
                            <div class="quiz-box__choice-description">
                                <div class="quiz-box__choice-letter-box">
                                    A
                                </div>
                                <div class="quiz-box__choice-answer-box">
                                    <p class="quiz-box__choice-answer">{{$choice->choice}}</p>
                                </div>
                            </div>
                        </label>
                        @endforeach
                    </div>
                    <div class="uk-alert-danger" uk-alert>
                        <a class="uk-alert-close"></a>
                        <p>lorem ipsum</p>
                    </div>
                </div>
                <hr class="quiz-box__divider">
                @endforeach
            </div>

0 likes
7 replies
Sinnbeck's avatar

Ok. So all of this is inside a form? Or are you using Javascript / ajax?

Sinnbeck's avatar

Then it should work. Inspect the html on the page and see if the inputs are rendered correctly and inside the form element

Snapey's avatar

looks ok, but for convenience I would name the radios;

name="question[{{$question->question_identifier}]choice"

View the source in your browser and check that everything is expanded out correctly.

Please or to participate in this conversation.