radfusion/app/Services/DocumentGenerator/Word.php
2025-01-09 13:33:31 +06:00

40 lines
1000 B
PHP

<?php
namespace App\Services\DocumentGenerator;
use App\Models\Study;
use App\Models\StudyReport;
use PhpOffice\PhpWord\IOFactory;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Shared\Html;
class Word
{
public static function make(Study $study, StudyReport $report)
{
$html = $report->getContent();
$phpWord = new PhpWord;
$section = $phpWord->addSection();
// Add HTML content to the section
Html::addHtml($section, $html, false, false);
// Save the document as a DOCX file
// $filename = 'report.docx';
$writer = IOFactory::createWriter($phpWord, 'Word2007');
ob_start();
$writer->save('php://output');
$content = ob_get_clean();
return $content;
$content = view('staff.reports.word', compact('study', 'report'))->render();
$filepath = ReportStorage::reportFilepath($study, '.docx');
Storage::put($filepath, $content);
return $filepath;
}
}