1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Reedware\LaravelBlueprints\Concerns; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Str; |
6
|
|
|
|
7
|
|
|
trait MorphsTo |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* Defines a Belongs To Column and Relationship. |
11
|
|
|
* |
12
|
|
|
* @param string $morphable |
13
|
|
|
* @param string|null $index |
14
|
|
|
* |
15
|
|
|
* @return \Reed\Blueprints\Columns |
|
|
|
|
16
|
|
|
*/ |
17
|
|
|
public function morphsTo($morphable, $index = null) |
|
|
|
|
18
|
|
|
{ |
19
|
|
|
// Define the ID |
20
|
|
|
$id = $this->morphsToIdColumn($morphable); |
21
|
|
|
|
22
|
|
|
// Define the Type |
23
|
|
|
$type = $this->morphsToTypeColumn($morphable); |
24
|
|
|
|
25
|
|
|
// Return the Columns |
26
|
|
|
return $this->newColumns([$id, $type]); |
|
|
|
|
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Defines a Belongs To Column and Relationship using a Big Integer. |
31
|
|
|
* |
32
|
|
|
* @param string $morphable |
33
|
|
|
* @param string|null $index |
34
|
|
|
* |
35
|
|
|
* @return \Reed\Blueprints\Columns |
36
|
|
|
*/ |
37
|
|
|
public function bigMorphsTo($morphable, $index = null) |
|
|
|
|
38
|
|
|
{ |
39
|
|
|
// Define the ID |
40
|
|
|
$id = $this->bigMorphsToIdColumn($morphable); |
41
|
|
|
|
42
|
|
|
// Define the Type |
43
|
|
|
$type = $this->morphsToTypeColumn($morphable); |
44
|
|
|
|
45
|
|
|
// Return the Columns |
46
|
|
|
return $this->newColumns([$id, $type]); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Defines a Morphs To ID Column. |
51
|
|
|
* |
52
|
|
|
* @param string $morphable |
53
|
|
|
* @param boolean $big |
54
|
|
|
* |
55
|
|
|
* @return \Illuminate\Support\Fluent |
56
|
|
|
*/ |
57
|
|
|
public function morphsToIdColumn($morphable, $big = false) |
58
|
|
|
{ |
59
|
|
|
return $this->belongsToColumn($this->getMorphableId($morphable), $big); |
|
|
|
|
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Defines a Big Morphs To ID Column. |
64
|
|
|
* |
65
|
|
|
* @param string $morphable |
66
|
|
|
* |
67
|
|
|
* @return \Illuminate\Support\Fluent |
68
|
|
|
*/ |
69
|
|
|
public function bigMorphsToIdColumn($morphable) |
70
|
|
|
{ |
71
|
|
|
return $this->morphToIdColumn($morphable, true); |
|
|
|
|
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Defines a Morphs To Type Column. |
76
|
|
|
* |
77
|
|
|
* @param string $morphable |
78
|
|
|
* @param boolean $big |
79
|
|
|
* |
80
|
|
|
* @return \Illuminate\Support\Fluent |
81
|
|
|
*/ |
82
|
|
|
public function morphsToTypeColumn($morphable, $big = false) |
|
|
|
|
83
|
|
|
{ |
84
|
|
|
return $this->string($this->getMorphableType($morphable), 255); |
|
|
|
|
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Drops a Belongs To Relationship. |
89
|
|
|
* |
90
|
|
|
* @param string $morphable |
91
|
|
|
* @param string|null $index |
92
|
|
|
* |
93
|
|
|
* @return void |
94
|
|
|
*/ |
95
|
|
|
public function dropMorphsTo($morphable) |
96
|
|
|
{ |
97
|
|
|
// Drop the ID Column |
98
|
|
|
$this->dropMorphsToIdColumn($morphable); |
99
|
|
|
|
100
|
|
|
// Drop the Type Column |
101
|
|
|
$this->dropMorphsToIndex($morphable); |
|
|
|
|
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Drops a Morphs To ID Column. |
106
|
|
|
* |
107
|
|
|
* @param string $morphable |
108
|
|
|
* |
109
|
|
|
* @return \Illuminate\Support\Fluent |
110
|
|
|
*/ |
111
|
|
|
public function dropMorphsToIdColumn($morphable) |
112
|
|
|
{ |
113
|
|
|
$this->dropBelongsToColumn($this->getMorphableId($morphable)); |
|
|
|
|
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Drops a Morphs To Type Column. |
118
|
|
|
* |
119
|
|
|
* @param string $morphable |
120
|
|
|
* |
121
|
|
|
* @return \Illuminate\Support\Fluent |
122
|
|
|
*/ |
123
|
|
|
public function dropMorphsToTypeColumn($morphable) |
124
|
|
|
{ |
125
|
|
|
$this->dropColumn($this->getMorphableType($morphable)); |
|
|
|
|
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Returns the Name of the Morphable ID Column. |
130
|
|
|
* |
131
|
|
|
* @param string $morphable |
132
|
|
|
* |
133
|
|
|
* @return string |
134
|
|
|
*/ |
135
|
|
|
public function getMorphableId($morphable) |
136
|
|
|
{ |
137
|
|
|
return $morphable . '_id'; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* Returns the Name of the Morphable Type Column. |
142
|
|
|
* |
143
|
|
|
* @param string $morphable |
144
|
|
|
* |
145
|
|
|
* @return string |
146
|
|
|
*/ |
147
|
|
|
public function getMorphableType($morphable) |
148
|
|
|
{ |
149
|
|
|
return $morphable . '_type'; |
150
|
|
|
} |
151
|
|
|
} |
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