Conditions | 3 |
Paths | 5 |
Total Lines | 27 |
Code Lines | 16 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php namespace VojtaSvoboda\UserExportPdf\Behaviors; |
||
14 | public function pdf($id) |
||
15 | { |
||
16 | $user = User::find($id); |
||
17 | if ($user === null) { |
||
18 | throw new ApplicationException('User not found.'); |
||
19 | } |
||
20 | |||
21 | $templateCode = Config::get('vojtasvoboda.userexportpdf::config.template', 'rainlab::user'); |
||
22 | $filename = Str::slug($user->name . '-' . $user->username) . '.pdf'; |
||
23 | |||
24 | try { |
||
25 | /** @var PDFWrapper $pdf */ |
||
26 | $pdf = app('dynamicpdf'); |
||
27 | |||
28 | $options = [ |
||
29 | 'logOutputFile' => storage_path('temp/log.htm'), |
||
30 | ]; |
||
31 | |||
32 | return $pdf |
||
33 | ->loadTemplate($templateCode, compact('user')) |
||
34 | ->setOptions($options) |
||
35 | ->download($filename); |
||
36 | |||
37 | } catch (Exception $e) { |
||
38 | throw new ApplicationException($e->getMessage()); |
||
39 | } |
||
40 | } |
||
41 | } |
||
42 |