1
1
1programmer2018-04-26 20:20:10
Laravel
1programmer, 2018-04-26 20:20:10

How to correctly display values ​​on a page in laravel?

Hi all.
There are 70 entries in the database.
I bring it out like this

@if(isset($questions))
            <ul>
                @foreach($questions as $question)
                    <li class="qName">{{ $question->question }}</li>
                    <ul>
                        <li><label><input name="a1" type="radio" value="a">Постоянно</label></li>
                        <li><label><input name="a2" type="radio" value="b">Иногда</label></li>
                        <li><label><input name="a3" type="radio" value="c">Время от времени</label></li>
                    </ul>
                @endforeach
            </ul>
        @endif

Each one should have 3 possible answers.
Now I get 3 answers, but I can only mark 3.
That is, I answer the first question 1 to the second question 2 to the third 3 if I answer the fourth, then the radiobutton will be removed from 1, how to organize it correctly?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
1
1programmer, 2018-04-26
@1programmer

Answer

<li><label><input name="answer_{{ $loop->iteration }}" type="radio" value="a">Постоянно</label></li>
                        <li><label><input name="answer_{{ $loop->iteration }}" type="radio" value="b">Иногда</label></li>
                        <li><label><input name="answer_{{ $loop->iteration }}" type="radio" value="c">Время от времени</label></li>

K
kupurim, 2018-04-26
@kupurim

<input name="a{{$question->id}" type="radio" value="a">

You have all the inputs get the same name.

I
iljaGolubev, 2018-04-27
@iljaGolubev

If you don't understand what the error is, make a test page without a blade on pure HTML.
Your error is not in Laravel at all. Read here .
Well, for copy-paste - I would do something like this:

<li><label><input name="question[{{$question->id}}]" type="radio" value="a">Постоянно</label></li>
<li><label><input name="question[{{$question->id}}]" type="radio" value="b">Иногда</label></li>
<li><label><input name="question[{{$question->id}}]" type="radio" value="c">Время от времени</label></li>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question