As I undestand you are returning an array of elements. The only way I believe you can do that is displaying them with the $key of the value. As
{{ $comments['section']['value '] }}
I think thats the correct syntax. Correct me if not.
But to do that you'll need to know the $key of the array.
Or you can use several @foreach giving them a condition inside.
@foreach($comments as $key => $value)
@if($key == 'desiredvalue')
{{ $value }}
@endif
@endforeach
Hope this helps.
Happy coding. Daniel
isabellelimot liked this reply
Hi, the code above are my controller here's my code in blade.
@foreach($comments as $key => $comment)
<tr>
<td>
<div class="card">
<div class="card-body">
{{$comment->content->raw}}
</div>
<div class="card-footer text-muted">
{{$comment->user->nickname}}
</div>
</div>
</td>
</tr>
@endforeach
I tried using your command. but I got an error saying that I Cannot use object of type stdClass as array..
That error is because you are trying to access properties of an object like if it was an array.
You can access an object property with:
$object->property;
And in an array would be:
$array['property'];
So try to switch those on your code.
I believe this would be the correct way:
@foreach($comments as $key => $comment)
<tr>
<td>
<div class="card">
<div class="card-body">
{{ $comment['content']['raw'] }}
</div>
<div class="card-footer text-muted">
{{ $comment['user']['nickname'] }}
</div>
</div>
</td>
</tr>
@endforeach
developer-abir liked this reply
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community