300, 'marginLeft' => 600, 'marginRight' => 600, 'colsNum' => 1, 'pageNumberingStart' => 1, 'orientation' => 'portrait' ]; public string $fontName = 'Times New Roman'; public int $fontSize = 10; public function __construct(string $template, array $data, array $options = []) { $template = "documents.word.{$template}"; parent::__construct($template, $data, $options); } public function file(): string { $template = view($this->template, $this->data); $phpWord = new PhpWord(); $phpWord->setDefaultFontName($this->fontName); $phpWord->setDefaultFontSize($this->fontSize); $section = $phpWord->addSection($this->options); Html::addHtml($section, $template->render(), false, false); try { $filePath = $this->makeFilePath('docx'); $objWriter = IOFactory::createWriter($phpWord); $objWriter->save(Storage::path($filePath)); return $filePath; } catch (Exception $e) { var_dump($e->getMessage()); } } public function asset(string $name = null) { return $this->makeAsset($this->file(), $name); } }