0

There is an issue in the answer section of this code. The question section works fine, it is just the question.. when dd($questionnaire) answer array is there, but no items are shown.

@extends('layouts.app')

@section('content')
<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-8">
            <div class="card">
                <div class="card-header">{{ $questionnaire->title }}</div>

                <div class="card-body">
                  <a class="btn btn-dark" href="/questionnaires/{{ $questionnaire->id }}/questions/create">Create Question</a>
                  <a class="btn btn-dark" href="/surveys/{{ $questionnaire->id }}-{{ Str::slug($questionnaire->title) }}">Complete Questionnaire</a>
                </div>
            </div>

            @foreach($questionnaire->questions as $question)
              <div class="card mt-3">
                  <div class="card-header">{{ $question->question }}</div>

                  <div class="card-body">
                    <ul class="list-group">
                      @foreach($question->answers as $answer)
                        <li class="list-group-item">{{ $answer->answers }}</li>
                      @endforeach
                    </ul>
                  </div>
              </div>
            @endforeach
        </div>
    </div>
</div>
@endsection
4
  • dd($questionnaire) containing the answers is not really relevant since you are looping through $question->answers for the answers, what does $question->answers contain if you dd() it? Commented May 11, 2020 at 14:58
  • "questions" => Illuminate\Database\Eloquent\Collection {#306 ▼ #items: array:3 [▼ 0 => App\Question {#310 ▼ #relations: array:1 [▼ "answers" => Illuminate\Database\Eloquent\Collection {#308 ▼ #items: [] } Commented May 11, 2020 at 15:07
  • Did you dd() $question or $question->answers? Looks more like $question to me. It looks like there are no answers for this question, since the answers collection is empty. Commented May 11, 2020 at 15:12
  • i dd ($question), there are ansers in the database but wont pull through Commented May 11, 2020 at 17:09

1 Answer 1

1

dd Function means die and debug so your script stops at this point. Nothing else runs after dd

Sign up to request clarification or add additional context in comments.

1 Comment

when i used it to see what data was being pulled through i then took it out the code, does this still effect it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.