Passed
Push — master ( 78eefe...74ab54 )
by Tobias
02:21
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
use App\Http\Controllers\Controller;
7
8
class docxMustacheExampleController extends Controller
9
{
10
    public function index(Request $request)
11
    {
12
        //copy the example doc file into your storage directory or corret this path
13
        $local_template_file = storage_path('example_template.docx');
14
15
        //define date to be replaced
16
        $data = [
17
            [
18
                'name'     => 'Someone Other',
19
                'captions' => '*[[DONOTESCAPE]]*<b>something bold</b><br />and so on',
20
                'img_url'  => '[IMG-REPLACE]http://placehold.it/350x150[/IMG-REPLACE]',
21
            ],
22
            [
23
                'name'     => 'Person X',
24
                'captions' => '*[[DONOTESCAPE]]*<b>something bold</b><br />and so on',
25
                'img_url'  => '[IMG-REPLACE]http://placehold.it/350x150[/IMG-REPLACE]',
26
            ],
27
            [
28
                'name'     => 'Person Y',
29
                'captions' => '*[[DONOTESCAPE]]*<b>something bold</b><br />and so on',
30
                'img_url'  => '[IMG-REPLACE]http://placehold.it/350x150[/IMG-REPLACE]',
31
            ],
32
        ];
33
34
        //call class
35
        $docx_creation = new \WrkLst\DocxMustache\DocxMustache(['items'=>$data], $local_template_file);
36
37
        //optionally change some setting before the class gets executed
38
        $docx_creation->storageDisk = 'local';
39
40
        //execute class
41
        $docx_creation->execute();
42
43
        //return path of generated docx file
44
        return [
45
            'docx_file' => $docx_creation->local_path.$docx_creation->template_file_name,
46
        ];
47
    }
48
}
49