Error: Trying to get a Property of non-object

Asked

Viewed 681 times

1

I am running the following iteration and getting the error Trying to get Property of non-object, being the code:

                    @if(isset($propostas))
                        @foreach($propostas as $p)
                            <tr>
                                <td>{{$p->proposta}}</td>
                                <td>{{$p->descricao}}</td>
                                <td>{{$p->valor}}</td>
                                <td>{{$p->data}}</td>
                                <td>
                                    <button style="border: 0px; background: transparent;" class="ver_proposta" value="{{$p->id}}">
                                        <span class="glyphicon glyphicon-edit"></span>
                                    </button>
                                </td>
                                <td>
                                    <div class="form-group">
                                        <select id="cbx_status" class="form-control">
                                            <option value="Analise" {{$p->status->situacao == "Analise" ? 'selected' : ''}}>Analise</option>
                                            <option value="Aprovado" {{$p->status->situacao == "Aprovado" ? 'selected' : ''}}>Aprovado</option>
                                            <option value="Atualizado" {{$p->status->situacao == "Atualizado" ? 'selected' : ''}}>Atualizado</option>
                                            <option value="Pausado" {{$p->status->situacao == "Pausado" ? 'selected' : ''}}>Pausado</option>
                                            <option value="Finalizado" {{$p->status->situacao == "Finalizado" ? 'selected' : ''}}>Finalizado</option>
                                        </select> 
                                    </div>
                                </td>
                            </tr>
                        @endforeach
                    @endif
  • Friend, you need to be more specific. In which line gives this error, where this information comes from?

2 answers

1

<select id="cbx_status" class="form-control" name="propostas">
        @foreach($propostas as $p)
          <option @if($p->status->situacao->id == $p->status->situacao->id) selected @endif value="{{$situacao->id}}">{{$situacao->nome}}</option>
        @endforeach
      </select>

Try something like this, I’ve had these problems too.

0

Probably the mistake is making in the relationship

$p->status

Check if all proposed relationships with status are filled. This usually happens when the named relationship is null so there is no situation for null status.

$p->status->situacao

Browser other questions tagged

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