| Conditions | 1 |
| Paths | 1 |
| Total Lines | 38 |
| Code Lines | 17 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 9 | public function index(Request $request) |
||
| 10 | { |
||
| 11 | //copy the example doc file into your storage directory or corret this path |
||
| 12 | $local_template_file = storage_path('example_template.docx'); |
||
| 13 | |||
| 14 | //define date to be replaced |
||
| 15 | $data = [ |
||
| 16 | [ |
||
| 17 | 'name' => 'Someone Other', |
||
| 18 | 'captions' => '*[[DONOTESCAPE]]*<b>something bold</b><br />and so on', |
||
| 19 | 'img_url' => '[IMG-REPLACE]http://placehold.it/350x150[/IMG-REPLACE]', |
||
| 20 | ], |
||
| 21 | [ |
||
| 22 | 'name' => 'Person X', |
||
| 23 | 'captions' => '*[[DONOTESCAPE]]*<b>something bold</b><br />and so on', |
||
| 24 | 'img_url' => '[IMG-REPLACE]http://placehold.it/350x150[/IMG-REPLACE]', |
||
| 25 | ], |
||
| 26 | [ |
||
| 27 | 'name' => 'Person Y', |
||
| 28 | 'captions' => '*[[DONOTESCAPE]]*<b>something bold</b><br />and so on', |
||
| 29 | 'img_url' => '[IMG-REPLACE]http://placehold.it/350x150[/IMG-REPLACE]', |
||
| 30 | ], |
||
| 31 | ]; |
||
| 32 | |||
| 33 | //call class |
||
| 34 | $docx_creation = new \WrkLst\DocxMustache\DocxMustache(['items'=>$data], $local_template_file); |
||
| 35 | |||
| 36 | //optionally change some setting before the class gets executed |
||
| 37 | $docx_creation->storageDisk = 'local'; |
||
| 38 | |||
| 39 | //execute class |
||
| 40 | $docx_creation->execute(); |
||
| 41 | |||
| 42 | //return path of generated docx file |
||
| 43 | return [ |
||
| 44 | 'docx_file' => $docx_creation->local_path.$docx_creation->template_file_name, |
||
| 45 | ]; |
||
| 46 | } |
||
| 47 | } |
||
| 48 |