Trying to get property of non-object when I use @if

  laravel, php

Error:

Trying to get property 'desp_indevida' of non-object (View: D: ...detalhamentoindex-debito.blade.php)

My code:

index-debito.blade

@foreach ($detalhamento as $value)
     <tr>
     @if(!is_null($value->despesa_id))
        @if($value->despesa->desp_indevida == 1)
            <td>Indevido</td>
        @elseif(isset($value->pago_aplicacao))
            <td>Pago Aplicação</td>
        @elseif(isset($value->indevidos_id))
            <td>Indevido</td>
        @else
            <td>Programada</td>
    @endif
@endforeach

Detalhamento.php

public function despesa()
{
    return $this->belongsTo(Despesa::class,'despesa_id','id');
}

This error happend just to some register

Source: Laravel

Leave a Reply