1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Terranet\Administrator\Traits\Module; |
4
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
|
|
|
6
|
|
|
use Terranet\Administrator\Collection\Group; |
7
|
|
|
use Terranet\Administrator\Collection\Mutable as MutableCollection; |
8
|
|
|
use Terranet\Administrator\Dashboard\Manager; |
9
|
|
|
use Terranet\Administrator\Decorators\Grid as GridDecorator; |
10
|
|
|
use Terranet\Translatable\Translatable; |
11
|
|
|
|
12
|
|
|
trait HasColumns |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* Fetch scaffold columns. |
16
|
|
|
* |
17
|
|
|
* @return MutableCollection |
18
|
|
|
*/ |
19
|
|
|
public function columns(): MutableCollection |
20
|
|
|
{ |
21
|
|
|
return $this->scaffoldColumns(); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Define the list of attributes visible on View model page. |
26
|
|
|
* |
27
|
|
|
* @return MutableCollection |
28
|
|
|
*/ |
29
|
|
|
public function viewColumns(): MutableCollection |
30
|
|
|
{ |
31
|
|
|
return $this->scaffoldColumns(); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* List of widgets. |
36
|
|
|
* |
37
|
|
|
* @return Manager |
38
|
|
|
*/ |
39
|
|
|
public function widgets(): Manager |
40
|
|
|
{ |
41
|
|
|
return new Manager(); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* List of cards. |
46
|
|
|
* |
47
|
|
|
* @return Manager |
48
|
|
|
*/ |
49
|
|
|
public function cards(): Manager |
50
|
|
|
{ |
51
|
|
|
return new Manager(); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Scaffold columns. |
56
|
|
|
* |
57
|
|
|
* @return MutableCollection |
58
|
|
|
*/ |
59
|
|
|
protected function scaffoldColumns(): MutableCollection |
60
|
|
|
{ |
61
|
|
|
return $this->collectColumns( |
62
|
|
|
$this->model() |
|
|
|
|
63
|
|
|
); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param $model |
68
|
|
|
* |
69
|
|
|
* @return MutableCollection |
70
|
|
|
*/ |
71
|
|
|
protected function collectColumns(Model $model = null): MutableCollection |
72
|
|
|
{ |
73
|
|
|
if (!$model) { |
74
|
|
|
return new MutableCollection([]); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
$pk = $model->getKeyName(); |
78
|
|
|
|
79
|
|
|
$fillable = array_merge( |
80
|
|
|
is_array($pk) ? $pk : [$pk], |
81
|
|
|
$model->getFillable() |
82
|
|
|
); |
83
|
|
|
$hidden = $model->getHidden(); |
84
|
|
|
|
85
|
|
|
if ($model instanceof Translatable && method_exists($model, 'getTranslatedAttributes')) { |
86
|
|
|
$fillable = array_merge($fillable, $model->getTranslatedAttributes()); |
87
|
|
|
$hidden = array_merge($hidden, $model->getTranslationModel()->getHidden()); |
|
|
|
|
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
$fillable = array_unique(array_diff($fillable, $hidden)); |
91
|
|
|
|
92
|
|
|
$elements = new MutableCollection($fillable); |
93
|
|
|
|
94
|
|
|
if (property_exists($this, 'includeDateColumns') |
95
|
|
|
&& $this->includeDateColumns |
96
|
|
|
&& count($dates = $model->getDates())) { |
97
|
|
|
// allow setting specific timestamp: created_at |
98
|
|
|
if (is_string($this->includeDateColumns)) { |
99
|
|
|
$dates = array_intersect($dates, [$this->includeDateColumns]); |
100
|
|
|
|
101
|
|
|
$elements = $elements->merge($dates); |
102
|
|
|
} else { |
103
|
|
|
// add timestamps group |
104
|
|
|
$elements->group('dates', function (Group $group) use ($dates) { |
105
|
|
|
$group->merge($dates); |
106
|
|
|
|
107
|
|
|
return $group; |
108
|
|
|
}); |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
return $elements->build( |
113
|
|
|
new GridDecorator($model) |
114
|
|
|
); |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths