|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
if (! function_exists('datatables')) { |
|
4
|
|
|
/** |
|
5
|
|
|
* Get datatables instance. |
|
6
|
|
|
* |
|
7
|
|
|
* @return \Yajra\Datatables\Datatables |
|
8
|
|
|
*/ |
|
9
|
|
|
function datatables() |
|
10
|
|
|
{ |
|
11
|
|
|
return app('datatables'); |
|
12
|
|
|
} |
|
13
|
|
|
} |
|
14
|
|
|
|
|
15
|
|
|
if (! function_exists('dt_render')) { |
|
16
|
|
|
/** |
|
17
|
|
|
* Render a view. |
|
18
|
|
|
* |
|
19
|
|
|
* @param string $view |
|
20
|
|
|
* @param array $data |
|
21
|
|
|
* @return string |
|
22
|
|
|
*/ |
|
23
|
|
|
function dt_render($view, $data = []) |
|
24
|
|
|
{ |
|
25
|
|
|
return view($view, $data)->render(); |
|
|
|
|
|
|
26
|
|
|
} |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
if (! function_exists('dt_label')) { |
|
30
|
|
|
/** |
|
31
|
|
|
* Display a label view. |
|
32
|
|
|
* |
|
33
|
|
|
* @param string $label |
|
34
|
|
|
* @param string $type |
|
35
|
|
|
* @return string |
|
36
|
|
|
*/ |
|
37
|
|
|
function dt_label($label, $type = 'info') |
|
38
|
|
|
{ |
|
39
|
|
|
return dt_render('datatables::label', compact('label', 'type')); |
|
40
|
|
|
} |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
if (! function_exists('dt_badge')) { |
|
44
|
|
|
/** |
|
45
|
|
|
* Display a badge view. |
|
46
|
|
|
* |
|
47
|
|
|
* @param string $label |
|
48
|
|
|
* @param string $type |
|
49
|
|
|
* @return string |
|
50
|
|
|
*/ |
|
51
|
|
|
function dt_badge($label, $type = 'info') |
|
52
|
|
|
{ |
|
53
|
|
|
return dt_render('datatables::badge', compact('label', 'type')); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
if (! function_exists('dt_check')) { |
|
58
|
|
|
/** |
|
59
|
|
|
* Display a checkbox view. |
|
60
|
|
|
* |
|
61
|
|
|
* @param bool $checked |
|
62
|
|
|
* @return string |
|
63
|
|
|
*/ |
|
64
|
|
|
function dt_check($checked = true) |
|
65
|
|
|
{ |
|
66
|
|
|
return dt_render('datatables::check', compact('checked')); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
if (! function_exists('currentUser')) { |
|
71
|
|
|
/** |
|
72
|
|
|
* Get current user instance. |
|
73
|
|
|
* |
|
74
|
|
|
* @param string|null $guard |
|
75
|
|
|
* @return \App\User |
|
76
|
|
|
*/ |
|
77
|
|
|
function currentUser($guard = null) |
|
78
|
|
|
{ |
|
79
|
|
|
return auth($guard)->user(); |
|
|
|
|
|
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
if (! function_exists('file_can_have_thumbnail')) { |
|
84
|
|
|
/** |
|
85
|
|
|
* Check if file is an image and can have thumbnail. |
|
86
|
|
|
* |
|
87
|
|
|
* @param string $file |
|
88
|
|
|
* @return bool |
|
89
|
|
|
*/ |
|
90
|
|
|
function file_can_have_thumbnail($file) |
|
91
|
|
|
{ |
|
92
|
|
|
return @exif_imagetype(substr($file, 7)); |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
if (! function_exists('html')) { |
|
97
|
|
|
/** |
|
98
|
|
|
* Get html builder instance. |
|
99
|
|
|
* |
|
100
|
|
|
* @return \Collective\Html\HtmlBuilder |
|
101
|
|
|
*/ |
|
102
|
|
|
function html() |
|
103
|
|
|
{ |
|
104
|
|
|
return app('html'); |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
if (! function_exists('form')) { |
|
109
|
|
|
/** |
|
110
|
|
|
* Get html builder instance. |
|
111
|
|
|
* |
|
112
|
|
|
* @return \Collective\Html\FormBuilder |
|
113
|
|
|
*/ |
|
114
|
|
|
function form() |
|
115
|
|
|
{ |
|
116
|
|
|
return app('form'); |
|
117
|
|
|
} |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
if (! function_exists('bytesToHuman')) { |
|
121
|
|
|
/** |
|
122
|
|
|
* Convert bytes to a human readable presentation. |
|
123
|
|
|
* |
|
124
|
|
|
* @param int $bytes |
|
125
|
|
|
* @return string |
|
126
|
|
|
*/ |
|
127
|
|
|
function bytesToHuman($bytes) |
|
128
|
|
|
{ |
|
129
|
|
|
$units = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB']; |
|
130
|
|
|
|
|
131
|
|
|
for ($i = 0; $bytes > 1024; $i++) { |
|
132
|
|
|
$bytes /= 1024; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
return round($bytes, 2) . ' ' . $units[$i]; |
|
136
|
|
|
} |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
if (! function_exists('file_ext_to_icon')) { |
|
140
|
|
|
/** |
|
141
|
|
|
* Get font-awesome icon by file ext. |
|
142
|
|
|
* |
|
143
|
|
|
* @param string $ext |
|
144
|
|
|
* @return string |
|
145
|
|
|
*/ |
|
146
|
|
|
function file_ext_to_icon($ext) |
|
147
|
|
|
{ |
|
148
|
|
|
$icons = [ |
|
149
|
|
|
'pdf' => 'fa-file-pdf-o', |
|
150
|
|
|
'doc' => 'fa-file-word-o', |
|
151
|
|
|
'docx' => 'fa-file-word-o', |
|
152
|
|
|
'ppt' => 'fa-file-powerpoint-o', |
|
153
|
|
|
'pptx' => 'fa-file-powerpoint-o', |
|
154
|
|
|
'xls' => 'fa-file-excel-o', |
|
155
|
|
|
'xlsx' => 'fa-file-excel-o', |
|
156
|
|
|
'csv' => 'fa-file-excel-o', |
|
157
|
|
|
'zip' => 'fa-file-archive-o', |
|
158
|
|
|
'tar' => 'fa-file-archive-o', |
|
159
|
|
|
'gz' => 'fa-file-archive-o', |
|
160
|
|
|
'rar' => 'fa-file-archive-o', |
|
161
|
|
|
'audio' => 'fa-file-audio-o', |
|
162
|
|
|
'mp3' => 'fa-file-audio-o', |
|
163
|
|
|
'wav' => 'fa-file-audio-o', |
|
164
|
|
|
'txt' => 'fa-file-code-o', |
|
165
|
|
|
'html' => 'fa-file-code-o', |
|
166
|
|
|
'php' => 'fa-file-code-o', |
|
167
|
|
|
'jpg' => 'fa-file-image-o', |
|
168
|
|
|
'jpeg' => 'fa-file-image-o', |
|
169
|
|
|
'png' => 'fa-file-image-o', |
|
170
|
|
|
'gif' => 'fa-file-image-o', |
|
171
|
|
|
'bmp' => 'fa-file-image-o', |
|
172
|
|
|
'tiff' => 'fa-file-image-o', |
|
173
|
|
|
'mov' => 'fa-file-movie-o', |
|
174
|
|
|
'mp4' => 'fa-file-movie-o', |
|
175
|
|
|
'avi' => 'fa-file-movie-o', |
|
176
|
|
|
]; |
|
177
|
|
|
|
|
178
|
|
|
if (in_array($ext, array_keys($icons))) { |
|
179
|
|
|
return $icons[$ext]; |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
|
|
return 'fa-file-o'; |
|
183
|
|
|
} |
|
184
|
|
|
} |
|
185
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: