Foreach with two bd lists. Laravel Street

Asked

Viewed 273 times

0

I read some articles and saw this way, but it is not correct giving the following error:

(1/1) Errorexception Undefined offset: 1

@foreach($palpites, $confrontos) as ($p, $c))
  <tr>    
    <td> {{ $p->diadojogo}} </td>
    <td> {{ $p->timea }} </td>
    <td> {{ $c->diadojogo}} </td>
    <td> {{ $c->resultado}} </td>      
  </tr>    
@endforeach
  • 3

    What articles have you read? Searched on official documentation? It doesn’t even contain this syntax you used.

  • Post the article where the foreach interacts in two lists?

1 answer

2


You can use it this way, I believe it will work for your situation:

<table>
    <thead>
        <tr>
            <th>coluna1P</th>
            <th>coluna2P</th>
            <th>coluna1C</th>
            <th>coluna2C</th>
        </tr>
    </thead>
    <tbody>
    @foreach($palpites as $index => $palpite)
        <tr>
            <td> {{ $palpite['diajogo'] }} </td>
            <td> {{ $palpite['timea'] }} </td>
            <td> {{ $confrontos[$index]['diajogo'] }} </td>
            <td> {{ $confrontos[$index]['resultado'] }} </td>
        </tr>
    @endforeach
    </tbody>
</table>

I believe it will only not work if the amounts of hunches and confrontations are not the same.

  • Its code gives error. both part and the other isolated. @foreach($palpites as $index => $palpite) (1/1) Fatalerrorexception Cannot use Object of type stdClass as array <tr> <td> {{ $palpite['diadojogo'] }} </td> <td> {{ $palpite['Timea'] }} </td> <<<<<tr> @ endforeach @foreach($picks as $index => $guess) <tr> <td> {{ $confrontations[$index]['diajogo'] }} </td> <td> {{ $confrontations[$index]['result'] }} </td> </tr> @endforeach

  • The error occurs due I am working with arrays and you are trying to access as object.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.