Loop over collection

If I do a print_r on $payments in my view then this is my result;

Array
(
[0] => AppModelsPayment Object
    (
        [connection:protected] => 
        [table:protected] => 
        [primaryKey:protected] => id
        [perPage:protected] => 15
        [incrementing] => 1
        [timestamps] => 1
        [attributes:protected] => Array
            (
                [Valued or Running] => R
                [Contract Title] => SERVICES AGREEMENT
                [Vendor ZIP] => A123GQ
            )

        [original:protected] => Array
            (
                [Valued or Running] => R
                [Contract Title] => SERVICES AGREEMENT
                [Vendor ZIP] => A123GQ
            )

        [relations:protected] => Array
            (
            )

        [hidden:protected] => Array
            (
            )

        [visible:protected] => Array
            (
            )

        [appends:protected] => Array
            (
            )

        [fillable:protected] => Array
            (
            )

        [guarded:protected] => Array
            (
                [0] => *
            )

        [dates:protected] => Array
            (
            )

        [casts:protected] => Array
            (
            )

        [touches:protected] => Array
            (
            )

        [observables:protected] => Array
            (
            )

        [with:protected] => Array
            (
            )

        [morphClass:protected] => 
        [exists] => 1
    )

[1] => AppModelsPayment Object
    (
        [connection:protected] => 
        [table:protected] => 
        [primaryKey:protected] => id
        [perPage:protected] => 15
        [incrementing] => 1
        [timestamps] => 1
        [attributes:protected] => Array
            (
                [Valued or Running] => R
                [Contract Title] => TST
                [Vendor ZIP] => A124YD
            )

        [original:protected] => Array
            (
                [Valued or Running] => R
                [Contract Title] => TST
                [Vendor ZIP] => A124YD
            )

        [relations:protected] => Array
            (
            )

        [hidden:protected] => Array
            (
            )

        [visible:protected] => Array
            (
            )

        [appends:protected] => Array
            (
            )

        [fillable:protected] => Array
            (
            )

        [guarded:protected] => Array
            (
                [0] => *
            )

        [dates:protected] => Array
            (
            )

        [casts:protected] => Array
            (
            )

        [touches:protected] => Array
            (
            )

        [observables:protected] => Array
            (
            )

        [with:protected] => Array
            (
            )

        [morphClass:protected] => 
        [exists] => 1
    )

[2] => AppModelsPayment Object
    (
        [connection:protected] => 
        [table:protected] => 
        [primaryKey:protected] => id
        [perPage:protected] => 15
        [incrementing] => 1
        [timestamps] => 1
        [attributes:protected] => Array
            (
                [Valued or Running] => R
                [Contract Title] => ONE
                [Vendor ZIP] => A238JW
            )

        [original:protected] => Array
            (
                [Valued or Running] => R
                [Contract Title] => ONE
                [Vendor ZIP] => A238JW
            )

        [relations:protected] => Array
            (
            )

        [hidden:protected] => Array
            (
            )

        [visible:protected] => Array
            (
            )

        [appends:protected] => Array
            (
            )

        [fillable:protected] => Array
            (
            )

        [guarded:protected] => Array
            (
                [0] => *
            )

        [dates:protected] => Array
            (
            )

        [casts:protected] => Array
            (
            )

        [touches:protected] => Array
            (
            )

        [observables:protected] => Array
            (
            )

        [with:protected] => Array
            (
            )

        [morphClass:protected] => 
        [exists] => 1
    )

I’m trying to print out the result in to a table. Something like;

@foreach($payments as $key => $payment)
  <tr>
     @foreach($payment as $subkey => $subpayment)
        <td>{{ $subkey }}</td>
    @endforeach
  </tr>
@endforeach

I can’t get my loop to work! I want to print out the three fields, one for each row in the table.


Source: laravel

Leave a Reply