Support the ongoing development of Laravel.io →
Views Blade

I have a model Object I have passed to the view one of the attributes is a array containing other associative arrays when I use @foreach on the outer array and try to retrieve a key from the resultant inner array Blade throws an error Illegal string offset Indeed the array seems to have been turned into a series of strings (if you do a var_dump) but they obv. don't have the keys associated them they just var_dump as String(3) xxx String(5) yyyyy

Anyone know how I would go about getting the inner loop value as an array?

Thanks in anticipation (new Laravel user)

Last updated 3 years ago.
0

Can you provide a sample code in which we can tweak?

Last updated 3 years ago.
0

Thanks for the help

       @foreach($place->attested[$counter] as $attestation)

            
         //so attestation at this point should be an array 
         //however it comes out as strings

        @endforeach

It is from the $place Model which when debugged looks like this https://www.dropbox.com/s/uelptxl707thd8t/Screen%20Shot%202014-02-25%20at%2012.36.59.png

Last updated 3 years ago.
0

What is $counter? Isn't it just @foreach($place->attested as $attestation)? Can you var_dump your $place->attested[$counter] or $place->attested objects?

Last updated 3 years ago.
0

@barryvdh thanks for the help

$counter is used cos I am trying to essentially link two ordered items this loop is inside another , I think by questioning that you have made me realise this is getting overly complicated for a view and the work would be much better done at a higher level

@foreach ($place->historicalForm as $historicalForm)

    <li><a href="#histform-<?php echo $counter;?>">{{ $historicalForm}}</a>

        <!-- attestations -->
        @if($counter<count($place->attested))
        @foreach($place->attested[$counter] as $attestation)

            <?php $att =  (array) $attestation;?>
            {{var_dump($att)}}

        @endforeach
        @endif
        <!--end -->

    </li>

    <?php $counter++;?>
@endforeach

this is what I was doing - which results in array(5) { ["histform"]=> string(5) "Ackle" ["sources"]=> string(2) "Ch" ["sourceId"]=> string(4) "bu15" ["dates"]=> string(4) "1228" ["attestation"]=> string(23) "'wood of Ackle' 1228 Ch" } from the var_dump

Last updated 3 years ago.
0

As discussed above -> I have now returned the inner array (attested) as a view variable therefore I can use counter to obtain info from that easily -- thanks to all for help

Last updated 3 years ago.
0

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.

© 2025 Laravel.io - All rights reserved.