Search code examples
laravelmpdf

Class 'Mpdf\Mpdf' not found (Laravel Job)


I have the following code for a laravel Job. It works just fine when in the Controller, but once I transferred it to a job, it fails with the error

Class 'Mpdf\Mpdf' not found

I have imported the class at the top of the job as I did with the controller so can't figure out why it can't find it.

<?php

    namespace App\Jobs;

    use Mpdf\Mpdf;
    use App\DocumentRequest;
    use Illuminate\Bus\Queueable;
    use Intervention\Image\Facades\Image;
    use Illuminate\Queue\SerializesModels;
    use Illuminate\Support\Facades\Storage;
    use Illuminate\Queue\InteractsWithQueue;
    use Illuminate\Contracts\Queue\ShouldQueue;
    use Illuminate\Foundation\Bus\Dispatchable;

    class ProcessUploads implements ShouldQueue
    {

    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    protected $uuid;

    public function __construct($uuid)
    {
        $this->uuid = $uuid;
    }


    public function handle()
    {
        $mpdf =  new Mpdf();

        $mpdf->WriteHTML($this->uuid);

        $mpdf->Output('Output.pdf', 'F');
    }
}

Solution

  • Steps to do for this type of errors:

    1. Check composer that this package is already installed
    2. Use the composer dump-autoload command to update autoload classes.
    3. Check the documentation of this package for the valid class call
    4. Restart the queue (because queue and tinker cache the code)