0

I'm trying to fetch data from database and pass this data to pdf view and download it.

I tried this code but its not working:

<a href="{{url('/download-PDF/'.$eventData->id)}}" class="btn btn-danger pull-right">Download PDF </a>

Route

Route::get('download-PDF/{id}', 'PDFController@pdf');

Controller

class PDFController extends Controller
{
public function pdf($id){
    $getEvent=Event::find($id);
    $eventId=$getEvent->id;


    if(isset($eventId)) {

        $eventData = Event::where('id', $eventId)->first();
        $getDays = Day::where('event_id', $eventId)->get();
        for ($i = 0; $i < count($getDays); $i++) {
            $dayId = $getDays[$i]->id;
            $schedule[$i] = DaySchedule::where('day_id', $dayId)->get();
        }

    }

    $pdf=PDF::loadView('pdf',['eventData' => $eventData, 'schedule' => $schedule]);

    return $pdf->download('event.pdf');
}
}

Config

'providers' => [
  Barryvdh\DomPDF\ServiceProvider::class,
 ]

 'aliases' => [
 'PDF' => Barryvdh\DomPDF\Facade::class,
  ]
João Mantovani
  • 2,230
  • 1
  • 21
  • 33
Jamal Ahmad
  • 571
  • 2
  • 9
  • 25
  • whats the error you getting? – Mr Singh Mar 22 '17 at 13:16
  • it execute for a while and then get this Error `Maximum execution time of 60 seconds exceeded` – Jamal Ahmad Mar 22 '17 at 13:19
  • http://stackoverflow.com/questions/30270316/how-to-solve-a-timeout-error-in-laravel-5 – Mr Singh Mar 22 '17 at 13:22
  • This is not necessarily a solution to your problem, but if you know that you will be able to execute a binary on the production server, I've found barryvdh/laravel-snappy to be much better (better rendering) than DomPDF. – wunch Mar 22 '17 at 23:07

1 Answers1

1

Are you getting any exception?

Here is a code I use for generating the pdfs:

Controller:

public function generateReport(TimetableRequest $request, $id) {
    $reportData = $this->prepareReportData($id, $request->startDate, $request->endDate);
    $pdf = App::make('dompdf.wrapper');
    $pdf->loadView('pdf.report', $reportData);
    return $pdf->download('report.pdf');
}

Config

'providers' => [
    ...
    Barryvdh\DomPDF\ServiceProvider::class,
    ],

'aliases' => [
    'App' => Illuminate\Support\Facades\App::class,
    ...
    'PDF' => Barryvdh\DomPDF\Facade::class,
    ]

Route

Route::get('projects/{id}/report', 'Controller@generateReport');