PDF in Laravel returning View selected

0

Hello, I'm using DomPDF to try to return a report in pdf, but every time I call the view it loads like it's in an infinite loop and nothing happens. Follow my code CourseController.php

public function downloadPDF($id)
    {
      $curso = Curso::find($id);
      $alunos = $curso->alunos;
      $pdf = PDF::loadView('curso.pdf', compact('curso', 'alunos'));
      return $pdf->download('invoice.pdf');

    }

My route is calling like this:

Route::get('/cursos/{id}/pdf','CursoController@downloadPDF');

And the view I want to call is pdf.blade.php

@extends('master')
@section('content')


<div class="container">

<h2>{{$curso->nome}}</h2>

    <br>
    <div class="pull-right">
    </div>
    <table class="table table-striped">
    <thead>
      <tr>
        <th>ID</th>
        <th>Nome</th>
        <th>Nascimento</th>
        <th>logradouro</th>
        <th>No</th>
        <th>Bairro</th>
        <th>Cidade</th>
        <th>Estado</th>
        <th>Dt. Criação</th>
      </tr>
    </thead>
    <tbody>
      @foreach($alunos as $value)
      <tr>
        <td>{{$value->id}}</td>
        <td>{{$value->nome}}</td>
        <td>{{$value->data_nascimento}}</td>
        <td>{{$value->logradouro}}</td>
        <td>{{$value->numero}}</td>
        <td>{{$value->bairro}}</td>
        <td>{{$value->cidade}}</td>
        <td>{{$value->estado}}</td>
        <td>{{ date( 'd/m/Y' , strtotime($value->created_at))}}</td>

      </tr>
      @endforeach
    </tbody>
  </table>
  </div>


@endsection

I was able to generate the pdf by putting only one

PDF GENERATED

, now I need to make it return the variables.     
asked by anonymous 27.03.2018 / 13:18

1 answer

0

What may be happening, is some variable that is used in your master is disrupting the printing of the pdf.

try to get the template, if it continues, try to debug the controller call by call, so you would have a certainty where the error is happening.

To debug the view, comment on blocks and see if any pdf is coming out.

    
27.03.2018 / 16:28