samedi 27 février 2016

Laravel 5.1 using collection methods inside blade

In my blade template I have the following $questionList collection

Collection {#322 
  #items: array:2 [
    0 => Question {#321 
      ....
      #attributes: array:7 [
        "job_id" => 3
        "question_id" => 0
        "question_text" => "test"
        "expected_answer" => 1
        "created_at" => "0000-00-00 00:00:00"
        "updated_at" => "0000-00-00 00:00:00"
      ]
    }
    1 => Question {#318 ▶}
  ]
}

In the template I have a for loop. How can I check if my collection has an item with a question_id equal to the index of the for loop and if it does how do I display the question_text for that question_id. I've tried chaining the following collection methods but they don't work?

@for ($i = 0; $i < 5; $i++)

    {!! Form::text("question_list[{$i}][question_text]", $questionList->where('question_id', $i)->get('question_text', null), ['class' => '']) !!}

@endfor



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire