Перейдите на белую страницу в браузере вместо загрузки PDF в laravel-dompdf - PullRequest
0 голосов
/ 19 февраля 2019

У меня проблема в laravel-dompdf.Я думаю, что мой код правильный, и я не знаю, почему он направляет на белую страницу вместо загрузки PDF.Он работает в другом контроллере, но здесь нет.

white page

Мой код в моем контроллере:

public function export_pdf()
{
    if(Auth::user()->campus_id == 0){
        $processes = Process::join('bags','processes.bag_id', '=', 'bags.id')
              ->join('stations','processes.station_id', '=', 'stations.id')
              ->select('bags.*','stations.*','processes.*')
              ->where('stations.campus_id', Session::get('test'))
              ->orderBy('processes.id', 'desc')
              ->get();


        // Send data to the view using loadView function of PDF facade
        $pdf = PDF::loadView('collectionReportspdf', compact('processes'));
        // If you want to store the generated pdf to the server then you can use the store function
        $pdf->save(storage_path().'_filename.pdf');
        // Finally, you can download the file using download function
        return $pdf->download('reports.pdf');
   }
   else{
       $processes = Process::join('bags','processes.bag_id', '=', 'bags.id')
              ->join('stations','processes.station_id', '=', 'stations.id')
              ->select('bags.*','stations.*','processes.*')
              ->where('stations.campus_id', Auth::user()->campus_id)
              ->orderBy('processes.id', 'desc')
              ->get();


       // Send data to the view using loadView function of PDF facade
       $pdf = PDF::loadView('collectionReportspdf', compact('processes'));
       // If you want to store the generated pdf to the server then you can use the store function
       $pdf->save(storage_path().'_filename.pdf');
       // Finally, you can download the file using download function
       return $pdf->download('reports.pdf');
   }

}

1 Ответ

0 голосов
/ 20 февраля 2019

Раньше мне приходилось рендерить PDF перед сохранением или выводом в браузер.

Попробуйте добавить следующее выше $pdf->save():

$pdf->render();

Если он все ещене работает, попробуйте заменить оператор return на echo.

...