具有数据库驱动程序的Laravel作业返回未找到的类

时间:2019-01-21 16:35:45

标签: laravel class jobs pdflib

我正在使用Laravel作业,该作业通过邮件处理特定的注册确认。

在作业的handle()函数中,我指的是生成PDF的另一个类的静态函数(TicketController):

public function handle()
{
    $this->ticket = TicketController::createPdf($this->customer);

    Mail::to($this->customer->email)->send(new CustomerAccepted($this->customer, $this->ticket));
}

如果我通过sync驱动程序运行此作业,则一切工作正常。但是有了database,我总是会收到错误消息

class 'PDFlib' not found

当然,该类是在我的TicketController中实现的,我也尝试将其直接实现到我的工作类中。

我也尝试过多次重启队列工作器,但是在使用database运行时,我总是得到相同的结果。

编辑:

TicketController.php

use App\Customer;
use PDFlib;

class TicketController extends Controller
{
    public function createPdf(Customer $customer) 
    {
        $p = new PDFlib();

        $p->set_option("errorpolicy=return");
        $p->set_option("stringformat=utf8");
        $p->set_option("searchpath={" . resource_path() . "assets/fonts" . "}");
        $p->set_option("spotcolorlookup=false");

        if ($p->begin_document(storage_path('app/xy.pdf'), "") == 0) {
            echo ("Error: " . $p->get_errmsg());
            exit(1);
        }
        // Loading template and filling with content

        $p->end_page_ext("");
        $p->end_document("");

        return storage_path('app/xy.pdf');
    }
}

编辑#2

我将完整的PDFlib功能直接添加到作业的handle(),但仍然遇到相同的错误class 'PDFlib' not found

编辑#3

仅意识到在本地运行驱动程序database并使用php artisan queue:listen监听队列就可以很好地工作。

我正在Laravel Forge和database驱动程序上运行该应用程序。尝试通过后台驻留程序工作程序设置队列,不使用后台程序工作程序则设置队列,但两种设置均无效。

0 个答案:

没有答案