Mysql
 sql >> Database >  >> RDS >> Mysql

Come posso ottenere un ID di sospensione separato in foreach loop?

Non capisco completamente il tuo codice solo con queste informazioni, ma prova quanto segue:

Aggiungi il form all'interno del ciclo foreach, per inviare una richiesta a un singolo oggetto Quiz.

Così:

@foreach($questions as $question)
    @if($id == $question->category_id)
        <legend> Quiz Of {{ $question->category->title }}</legend>
        <div class="jumbotron">
            <form method="POST" action="{{ url('/store-quiz') }}" id="quiz_module">
                <input type="hidden" name="user_id" value="{{ auth()->user()->id }}">
                <input type="hidden" name="category_id" value="{{ $question->category_id }}">
                <input type="hidden" name="question_id" value="{{ $question->id }}">
                <h4> 
                    Question {{ $question->id }}
                </h4>
                <h3>
                    {{ $question->question }}
                </h3><br>
                <h5>
                    &emsp;<input type="radio" name="user_answer" class="form-check-input"  value="{{ $question->option_a }}">{{ $question->option_a }}<br>
                    &emsp;<input type="radio" name="user_answer" class="form-check-input" value="{{ $question->option_b }}">{{ $question->option_b }}<br>
                    &emsp;<input type="radio" name="user_answer" class="form-check-input" value="{{ $question->option_c }}">{{ $question->option_c }}<br>
                    &emsp;<input type="radio" name="user_answer" class="form-check-input" value="{{ $question->option_d }}">{{ $question->option_d }}<br>
                </h5>
                <button type="submit" class="btn btn-primary">Submit</button>
            </form>
        </div>
    @endif
@endforeach