Passed
Pull Request — master (#10)
by Tobias
02:25
created

docxMustacheExampleController::index()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 38
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 38
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 17
nc 1
nop 1
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use Illuminate\Http\Request;
6
7
class docxMustacheExampleController extends Controller
8
{
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