I have an array that i want to return from the controller to the view.But unable to retrieve that. If i dump my array it looks like this:
array:121 [▼
0 => array:10 [▼
"ProcedureName" => "eye"
"Status" => "referred"
"PreferredDate" => "12/12/2018"
"PreferredCity" => "Bangalore"
"BookingId" => "EZBK000126"
"Documents" => ""
"Name" => "vik kon"
"Age" => 62
"Gender" => "male"
"Mob" => "1110002223"
]
1 => array:10 [▼
"ProcedureName" => "eye"
"Status" => "referred"
"PreferredDate" => "12/12/2018"
"PreferredCity" => "mysore"
"BookingId" => "EZBK000125"
"Documents" => ""
"Name" => "vik kon"
"Age" => 62
"Gender" => "male"
"Mob" => "9146178526"
]
So i want to get it to show inside my view .Currently my code looks like this :
@foreach($new_records as $new_recordss)
<tr>
<td scope="col">{{ $new_recordss->ProcedureName }}</td>
<td scope="col">{{ $new_recordss->Status }}</td>
<td scope="col">{{ $new_recordss->Age }}</td>
<td scope="col"><div class="btn-group">
</div>
</td>
</tr>
@endforeach
But this gives the following error:
Trying to get property of non-object
That's because an array is not an object.
// -> is for object
<td scope="col">{{ $new_recordss->ProcedureName }}</td>
// [] is for array
<td scope="col">{{ $new_recordss['ProcedureName'] }}</td>
Thus this should work:
<td scope="col">{{ $new_recordss['ProcedureName'] }}</td>
<td scope="col">{{ $new_recordss['Status'] }}</td>
<td scope="col">{{ $new_recordss['Age'] }}</td>
The reason why
{{ $new_recordss->ProcedureName }}
would not work is because -> operator is used to access an Object. Notice that you get the following error:
Trying to get property of non-object
Because you have an array with 121 arrays in it. Therefore in order to access this associative array, you would use
{{ $new_recordss['ProcedureName'] }}
Here, the 'ProcedureName' is simply the key name and we are telling the array to fetch it's value. I hope this answers your question.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.