GeneratePdfDocument::class, 'word' => GenerateWordDocument::class ]; public static function generate(string $type, string $template, array $data, array $options = []) { return ($class = self::$classes[$type] ?? null) ? new $class($template, $data, $options) : null; } public function __construct(string $template, array $data, array $options = []) { $this->template = $template; $this->data = $data; $this->options = array_merge($this->options, $options); } public function makeFilePath($ext): string { $fileName = Str::lower(Str::random()); $dir = "documents/generated/{$fileName[0]}"; Storage::makeDirectory($dir); return "{$dir}/{$fileName}.{$ext}"; } public function makeAsset($path, $name) { return (new DocumentDownloadService())->makeAsset($path, $name); } }