Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mateog98's avatar

How can i generate a pdf of a certain ticket?

Im trying to generate a pdf to download or print of a certain ticket by passing an id.

So i did the following:

public function TicketPdf($id){
        $date = Ticket::find($id);           
    }

To identify the ticket i want to generate the pdf of.

This is my pdf view i want to generate for the specific ticket:

@extends('backend.layouts.master')

@section('content')

      </div><!-- /.col -->
      <div class="col-sm-6">
        <ol class="breadcrumb float-sm-right">
          <li class="breadcrumb-item"><a href="{{ route('home') }}">Home</a></li>
          <li class="breadcrumb-item">Ventas</li>
          <li class="breadcrumb-item">Pagos Recibidos</li>
        </ol>
      </div><!-- /.col -->
    </div><!-- /.row -->
  </div><!-- /.container-fluid -->
</div>
<!-- /.content-header -->

<!-- Main content -->
<section class="content">
  <div class="container-fluid">
    <!-- Main row -->
    <div class="row">
      <!-- Left col -->
      <section class="col-md-12">
        <!-- Custom tabs (Charts with tabs)-->
        <div class="card" style="background-image: linear-gradient(200deg, #070525ce 1%, rgb(1, 0, 5)100%);">
          <div class="card-header">
             <h3 class="font-weight-light text-white">Pagos Recibidos
                 <a class="btn bg-white float-right btn-sm" href="" target="_blank"><i class="fa fa-download"></i> DownloadPDF</a>
             </h3>
            </div>
          </div><!-- /.card-header -->
          <div class="card-body">
            <table id="example1" class="table table-bordered table-hover">
                <thead class="thead">
                    <tr>
                        <th>Cliente</th>
                        <th>Numero Factura</th>
                        <th>Fecha</th>
                        <th>Monto</th>
                        <th>Ver</th>
                    </tr>
                </thead>
                <tbody>
                    @php
                    $total_paid = '0';
                    @endphp
                    @foreach($allData as $key => $payment)
                    <tr>
                        <td>
                            {{$payment['customer']['name']}}
                            {{$payment['customer']['mobile_no']}}-{{ $payment['customer']['address'] }}
                        </td>
                        <td>{{$payment['invoice']['invoice_no'] }}</td>
                        <td>{{date('d-m-Y', strtotime($payment['invoice']['date']))}}</td>
                        <td>{{$payment->paid_amount}}</td>
                        <td>
                          <a title="details" class="btn btn-sm btn-success" href="{{ route('customers.paid.pdf',$payment->invoice_id) }}" target="_blank">
                            <i class="fa fa-eye"></i></a>
                        </td>
                        @php
                        $total_paid += $payment->paid_amount;
                       @endphp
                    </tr>
                    @endforeach
                  </tbody>
              </table>
              <table class="table table-bordered table-hover">
                <tbody>
                    <tr>
                        <td colspan="5" style="text-align: right; font-weight:bold;">Total</td>
                        <td><strong>{{ $total_paid }}</strong></td>
                    </tr>
                </tbody>
             </table>
          </div><!-- /.card-body -->
        </div>
        <!-- /.card -->
      </section>
      <!-- right col -->
    </div>
    <!-- /.row (main row) -->
  </div><!-- /.container-fluid -->
</section>
<!-- /.content -->
@endsection

How can i do so that when i click on a generate pdf button and passing to it the route to generate this pdf. So i dont know in my method how to make the logic to dompdf and how to generate it

0 likes
3 replies
jlrdw's avatar

Did you see the loadView in the documentation.

mateog98's avatar

@jlrdw Yes;

This is my method updated:

  public function TicketPDF(){
    $detailData = Ticket::find($id);
    $pdf = PDF::loadview('backend.ticket.ticket-pdf');
    return $pdf->download('ticket.pdf');
}

And this is my route:

 Route::get('/ticket-pdf/{id}','Backend\TicketController@TicketPDF')->name('tickets.pdf');

And this is the button where i pass the id:

  <a class="btn bg-white float-right btn-sm" href="{{route('tickets.pdf', $ticket->id)}}" target="_blank"><i class="fa fa-download"></i> Descargar PDF</a>

But when i click on it i get:

 Maximum execution time of 60 seconds exceeded

But if in my web.php i generate a random pdf with no id involved it works and i dont know why:

 Route::get('/prueba', function(){
//return view('backend.ticket.test'); 
$pdf = PDF::loadview('backend.ticket.ticket-pdf');
return $pdf->download('ticket.pdf');

  });

Please or to participate in this conversation.