Foreach nestled with Blade in Laravel

Asked

Viewed 204 times

0

I need to display in a report three nested information and the idea is to display releases of a balance sheet, this balance sheet belongs to a plan of accounts and the plan of accounts belongs to a group.

So the following should appear on the screen:

Account plan 1

  • Group 1
    • toss 1
    • toss 2
  • Group 2
    • toss 1
    • Chart of accounts 2
  • Group 3
    • toss 1
    • toss 2

I’m using DBQuery to obtain the data in the Backend, making Join between all tables, but always error.

privatefunctionBalanceteLancamentosPeriodo($inicio,$fim,$condominio_id,$plano_conta_id,$grupo)
{
    return$this->balancete_lancamento
     ->join('balancetes','balancetes.id','=','balancete_lancamentos.balancete_id')
     ->join('condominios','balancetes.condominio_id','=','condominios.id')
     ->join('grupos','grupos.plano_de_conta_id','=','balancete_lancamentos.plano_contas_id')
     ->select('balancete_lancamentos.historico','balancete_lancamentos.valor','balancete_lancamentos.plano_contas_id')
     ->where('condominios.id',$condominio_id)
     ->whereBetween('data_lancamento',[$inicio,$fim])
     ->where('balancete_lancamentos.plano_contas_id',$plano_conta_id)
     ->where('grupos.id',$grupo)
     ->orderBy('data_lancamento','asc')
     ->get();
}

I’m trying to display the data on the front as follows:

@foreach($lancamentos as $key => $value)
    {{ $key }} <br>
    @foreach($value as $sub_key => $sub_value)
        {{ $sub_key }} <br>
        @foreach($sub_value as $a)
            {{ $a }}
        @endforeach
    @endforeach
@endforeach

I’m getting the error: Method Illuminate View View::__toString() must not throw an Exception, Caught Errorexception: Invalid argument supplied for foreach()

When I remove the last @foreach() I get the return of the index number of the array and the property of the array, as in the image

inserir a descrição da imagem aqui

  • which error gives ?

  • This would be very quiet if you use the Eloquent instead of DB, because in relationships already comes the information that works for screen mounting

  • added the error and more information. The idea is that I can access the item that corresponds to "type", for example.

No answers

Browser other questions tagged

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