Support the ongoing development of Laravel.io →
Views Blade Laravel
Last updated 2 years ago.
0

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

Last updated 4 years ago.

isabellelimot liked this reply

1

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..

0

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

1

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.