forked from kriskbx/gitlab-time-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmacros.php
More file actions
29 lines (25 loc) · 871 Bytes
/
macros.php
File metadata and controls
29 lines (25 loc) · 871 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php
\Illuminate\Support\Collection::macro('toString', function ($params = []) {
return collect($this->items)
->map(function ($value) use ($params) {
if ( ! is_object($value) && ! is_array($value)) {
return $value;
}
if (is_array($value)) {
return json_encode($value);
}
try {
return call_user_func_array([$value, 'toString'], [$params]);
} catch (Exception $e) {
try {
return call_user_func([$value, 'toJson']);
} catch (Exception $e) {
return json_encode($value);
}
}
})
->implode(@$params['delimiter'] ?: '');
});
\Illuminate\Support\Collection::macro('firstLevelToArray', function () {
return $this->items;
});