0

我的数据库中有大约 1500 名学生,我需要为每个学生生成一张发票。为此,我正在使用这个库https://github.com/barryvdh/laravel-snappy。当我尝试生成时,出现此错误:

未创建文件“/var/www/skmpastebimaslt/public_html/storage/checks/24767 Dominykas Butkevičius 1581703819.pdf”(命令:/usr/local/bin/wkhtmltopdf --lowquality '/tmp/knp_snappy5e46e28b5d61f2.13362077.html' '/var/www/skmpastebimaslt/public_html/storage/checks/24767 Dominykas Butkeviius 1581703819.pdf')。

https://gyazo.com/3a3f60713601a663a1360cd65fee9914

为四个用户生成发票,然后应用程序崩溃。最有趣的是,即使错误说文件不是创建但它是创建的,我可以在我的存储文件夹中找到它。

我的代码:

public function saveCheckPdf(Student $student, Check $check = null, $fileName = null)
{
    if (empty($fileName)) {
        $fileName = 'kvitas_' . time() . '.pdf';
    }
    $path = storage_path('checks/' . $fileName . '.pdf');
    $this->renderCheckPdf($student, $check)->save($path);
    return $path;
}

private function renderCheckPdf(Student $student, Check $check = null)
{
    $bills = $this->billRepository->getCurrentSeasonBills($student->id);
    $payments = $this->paymentRepository->getCurrentSeasonPayments($student->id);

    $fileName = $student->fullname . ' kvitas';
    $billsSum = $bills->sum('sum');
    $paymentsSum = $payments->sum('sum');

    if (empty($check)) {
        $check = !empty($student->checks[0]) ? $student->checks[0] : false;
    }

    return newPDF::loadView('student.check_pdf', compact('student', 'payments', 'bills', 'billsSum', 'paymentsSum', 'fileName', 'check'));
}

然后我只是遍历每个用户并像这样在我的控制器中调用 saveCheckPdf 方法

$this->pdfService->saveCheckPdf($student, null, $student->id . ' ' . $student->fullname . ' ' . time());

也许有人面临同样的问题?

4

0 回答 0