I need to click a button to generate multiple docx with a same template, but only one docx is created. Any idea?????
collect($params['item_ids'])->map(function($item_id) {
$template = resource_path('templates/letter_template.docx');
$docx = new \Phpdocx\Create\CreateDocxFromTemplate($template);
$data = [some data created by $item_id];
$docx->replaceVariableByText($data, ['target' => 'document']);
$file_name = implode('-', [
Carbon::now()->format('ymd'),
'letter',
rand(),
]);
$docx->createDocxAndDownload($file_name, true);
});