<?php

namespace app\common;

//use Barryvdh\DomPDF\Facade\Pdf;
use Dompdf\Dompdf;

class File
{
    public static function exportPdf($content, $fileName)
    {
        $dompdf = new Dompdf();
        $dompdf->loadHtml($content);
        $dompdf->setPaper('A4', 'portrait');
        $dompdf->render();
        $pdfData = $dompdf->output();

        $savePath = public_path('storage/files/') . date('Ymd') . '/pdf';
        if (!is_dir($savePath)) {
            mkdir($savePath, 0777, true);
        }
        $filePath = $savePath . '/' . $fileName;
        file_put_contents($filePath, $pdfData);

        $url = getenv('STORAGE_DOMAIN') . '/storage/files/' . date('Ymd') . '/pdf/' . $fileName;

        return $url;
    }
}