Error generating PDF, Undefined variable: o (View:

Asked

Viewed 49 times

-4

  metodo gera pdf: 
  ordemController

 $ordens = Ordem::all();
 return \PDF::loadView('ordem.detalhes', compact('ordens'))
->setPaper('a4', 'landscape')
 ->stream('export.pdf');


  view
  <h1 class="text-warning">Ordem numero: {{$o->cliente_id}}</h1>

 <ul>
 <li>
    <b>Cliente:</b>  {{ $o->cliente->nome}}
</li>

<li>
    <b>Telefone:</b>  {{ $o->cliente->telefone}}
</li>

<li>
    <b>Data:</b> {{ $o->data }}
</li>

<li>
    <b>Problema:</b> {{ $o->problema }}
</li>

<li>
    <b>Valor :</b> R$ {{ $o->valor }}
</li>

<li>
    <b>Produto incluso :</b>  {{ $o->produto->nome}}
</li>

<li>
    <b>Tipo de servico :</b>  {{ $o->servico->nome}}
</li>


listing view:

 <div class="container-fluid">
  <table class="table table-condensed table-striped table-bordered
  table-hover"> 
   <tr>
    <th>Nome</th>   
    <th> Descrição</th>
    <th class="text-right"> Valor entrada </th>
    <th class="text-right"> Valor saída</th>
    <th class="text-right"> Qtd. estoque </th>
    <th class="text-center">Opções</th>

     </tr>

@foreach($produtos as $p)
<tr class="{{$p->qtd_estoque <=2?'danger':''}}">
    <td>{{$p->nome}}</td>   
    <td>{{$p->descricao}}</td>
    <td class="text-right">{{$p->valor_entrada}}</td>
    <td class="text-right">{{$p->valor_saida}}</td>
    <td class="text-right">{{$p->qtd_estoque}}</td>
    <td class="text-center">

        <div class="btn-group" role="group">
        <a href="/ordem/detalhes/ <?=$o->id ?>" class="btn btn-info btn-sm">
            <span class="glyphicon glyphicon-eye-open"></span>
        </a>
  • First of all, could you better define your problem? Second could post your full view?

  • Method works only in list view

  • You use the wrong website read: 1, 2

1 answer

0

Note that the warning indicates that the variable "$the" is undefined. That is, it does not exist.

This warning is displayed every time you try to use a variable that does not exist.

And in your code, note that in the following section, you define that the variable to be passed to the view is the "orders".

In the following passage:

 loadView('ordem.detalhes', compact('ordens'))

And in the view you call the variable "$the" that doesn’t exist.

Change the variable "$the" called in the view by the variable $orders which has been passed to view.

And to verify the existence of a variable before using it, the function isset() .

Example:

if( isset($variavel) ){
   // faz alguma coisa
}

Function reference isset()

http://php.net/manual/en/function.isset.php

Browser other questions tagged

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