Search code examples
laraveldompdf

DOM/PDF error - Non-static method Barryvdh\DomPDF\PDF::download() should not be called statically


My Controller is this:

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Barryvdh\DomPDF\Facade as PDF;
class PrintPDF extends Controller
{
    
    public function print(){
       $details =['title' => 'test'];
       $pdf = PDF::loadView('textDoc', $details);
       return $pdf::download('this.pdf');
    }
}

My routes

Route::get('/print', 'PrintPDF@print');

when accessing localhost/print I get an error

Non-static method Barryvdh\DomPDF\PDF::download() should not be called statically

I followed the install instructions on their site. I have tried to change my controller adding use PDF, instead of use Barryvdh\DomPDF\Facade as PDF; Yet the error persists


Solution

  • make the function call like this

    return $pdf->download('invoice.pdf');