1 | <?php |
||
17 | trait Versionable |
||
18 | { |
||
19 | // You can add these properties to you versionable model |
||
20 | //protected $versionable = []; |
||
21 | //protected $dontVersionable = ['*']; |
||
22 | |||
23 | 5 | public static function bootVersionable() |
|
37 | |||
38 | 5 | private static function createVersionForModel(Model $model): void |
|
45 | |||
46 | /** |
||
47 | * @return \Illuminate\Database\Eloquent\Relations\MorphMany |
||
48 | */ |
||
49 | 5 | public function versions(): MorphMany |
|
53 | |||
54 | /** |
||
55 | * @return \Illuminate\Database\Eloquent\Relations\MorphOne |
||
56 | */ |
||
57 | 3 | public function lastVersion(): MorphOne |
|
61 | |||
62 | /** |
||
63 | * @param int $id |
||
64 | * |
||
65 | * @return \Illuminate\Database\Eloquent\Model|null |
||
66 | */ |
||
67 | 1 | public function getVersion($id) |
|
71 | |||
72 | /** |
||
73 | * @param int $id |
||
74 | * |
||
75 | * @return mixed |
||
76 | */ |
||
77 | 1 | public function revertToVersion($id) |
|
81 | |||
82 | /** |
||
83 | * @param int $keep |
||
84 | */ |
||
85 | 5 | public function removeOldVersions(int $keep): void |
|
93 | |||
94 | 1 | public function removeAllVersions() |
|
98 | |||
99 | /** |
||
100 | * @return bool |
||
101 | */ |
||
102 | 5 | public function shouldVersioning(): bool |
|
106 | |||
107 | /** |
||
108 | * @return array |
||
109 | */ |
||
110 | 5 | public function getVersionableAttributes(): array |
|
131 | |||
132 | /** |
||
133 | * @param array $attributes |
||
134 | * |
||
135 | * @return $this |
||
136 | * |
||
137 | * @throws \Exception |
||
138 | */ |
||
139 | public function setVersionable(array $attributes) |
||
149 | |||
150 | /** |
||
151 | * @param array $attributes |
||
152 | * |
||
153 | * @return $this |
||
154 | * |
||
155 | * @throws \Exception |
||
156 | */ |
||
157 | public function setDontVersionable(array $attributes) |
||
167 | |||
168 | /** |
||
169 | * @return array |
||
170 | */ |
||
171 | 5 | public function getVersionable(): array |
|
175 | |||
176 | /** |
||
177 | * @return array |
||
178 | */ |
||
179 | public function getDontVersionable(): array |
||
183 | |||
184 | /** |
||
185 | * @return string |
||
186 | */ |
||
187 | 5 | public function getVersionStrategy() |
|
191 | |||
192 | /** |
||
193 | * @param string $strategy |
||
194 | * |
||
195 | * @return $this |
||
196 | * |
||
197 | * @throws \Exception |
||
198 | */ |
||
199 | 1 | public function setVersionStrategy(string $strategy) |
|
209 | |||
210 | /** |
||
211 | * @return string |
||
212 | */ |
||
213 | 5 | public function getVersionModel(): string |
|
217 | |||
218 | /** |
||
219 | * @return string |
||
220 | */ |
||
221 | 5 | public function getKeepVersionsCount(): string |
|
225 | |||
226 | /** |
||
227 | * Get the versionable attributes of a given array. |
||
228 | * |
||
229 | * @param array $attributes |
||
230 | * |
||
231 | * @return array |
||
232 | */ |
||
233 | 5 | public function versionableFromArray(array $attributes): array |
|
245 | } |
||
246 |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.