jeudi 31 mai 2018

How to fetch an Aray in laravel using MongoDB database

I have the following document

{
    "_id" : ObjectId("5b1005f8f2468f0fe0007c46"),
    "question" : "my question",
    "answere" : " my answere",
    "options" : [
            {
                    "A" : "dfd"
            },
            {
                    "B" : "fdf"
            },
            {
                    "C" : "fdfdf"
            }
    ],
    "explanation" : "my Explanation",
    "correctans" : "A",
    "updated_at" : ISODate("2018-05-31T14:26:00Z"),
    "created_at" : ISODate("2018-05-31T14:26:00Z")
 }

And now I want to print the options how can this possible. I am trying this.

@foreach($questions as $key => $question)
<tr>                         
 <td></td>  
 <td></td>
 <td></td>
 <td></td>
 <td>
    @foreach($question->options as $key => $option )
       
    @endforeach
  </td>
  <td></td>
</tr>
@endforeach

getting this error

"Trying to get property 'A' of non-object

Fetching the data using this

$questions = Question::all();

Please tell how to fetch



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2H6ZjyF
via IFTTT

Aucun commentaire:

Enregistrer un commentaire