laraveldompdf

laravel domPdf works on localhost but not on server


I'm using DomPDF to generate pdf on my laravel app, and it works fine on the localhost, but when i upload it to my server it shows:

Class "Barryvdh\DomPDF\Facade\Pdf" not found

this is the function i'm using

use Barryvdh\DomPDF\Facade\Pdf;

...

public function indexPDF(Request $request)
    {
        $date = new Carbon($request->date);
        $startdate = $date->startOfDay();
        $enddate = $date->copy()->endOfDay();

        $requisitions = Requisition::where('date_start','<',$enddate)
            ->where('date_end','>',$startdate)->orderBy('date_start','ASC')
            ->get();

 -->    $pdf = Pdf::loadView('pdf.requisitions',compact('date','requisitions'));

        return $pdf->download('requisições_do_dia.pdf');

        // return view('pdf.requisitions',compact('date','requisitions'));
    }

does anyone know what the problem might be?

uploaded all the necessary files but still get the same error


Solution

  • Solved it. Managed to create the autoload via:

    php artisan vendor:publish --provider="Barryvdh\DomPDF\ServiceProvider"
    

    which wasn't running at first because of the config/app.php configuration because most tutorials instruct to add these lines to that file

    'providers' => [ 
        // ... Barryvdh\DomPDF\ServiceProvider::class, 
    ], 
    'aliases' => [ 
        // ... 'PDF' => Barryvdh\DomPDF\Facade::class, 
    ],
    

    but it wan's working, so i removed those lines and the publish command worked, after that that upload to server and it worked on the server as well.