0
我試圖從數據庫中獲取數據並將這些數據傳遞給pdf查看並下載它。如何在laravel 5.4下載PDF?
我想這個代碼,但它不工作:
<a href="{{url('/download-PDF/'.$eventData->id)}}" class="btn btn-danger pull-right">Download PDF </a>
路線
Route::get('download-PDF/{id}', '[email protected]');
控制器
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');
}
}
配置
'providers' => [
Barryvdh\DomPDF\ServiceProvider::class,
]
'aliases' => [
'PDF' => Barryvdh\DomPDF\Facade::class,
]
你得到的錯誤是什麼? – Learner
它執行一段時間,然後得到這個錯誤'超過60秒的最大執行時間' –
http://stackoverflow.com/questions/30270316/how-to-solve-a-timeout-error-in-laravel-5 – Learner