1 | <?php |
||
17 | trait Versionable |
||
18 | { |
||
19 | // You can add these properties to you versionable model |
||
20 | //protected $versionable = []; |
||
21 | //protected $dontVersionable = ['*']; |
||
22 | |||
23 | public static function bootVersionable() |
||
37 | |||
38 | private function createVersionForModel(Model $model): void |
||
45 | |||
46 | /** |
||
47 | * @return \Illuminate\Database\Eloquent\Relations\MorphMany |
||
48 | */ |
||
49 | public function versions(): MorphMany |
||
53 | |||
54 | /** |
||
55 | * @return \Illuminate\Database\Eloquent\Relations\MorphOne |
||
56 | */ |
||
57 | public function lastVersion(): MorphOne |
||
61 | |||
62 | /** |
||
63 | * @param int $id |
||
64 | * |
||
65 | * @return \Illuminate\Database\Eloquent\Model|null |
||
66 | */ |
||
67 | public function getVersion($id) |
||
71 | |||
72 | /** |
||
73 | * @param int $id |
||
74 | * |
||
75 | * @return mixed |
||
76 | */ |
||
77 | public function revertToVersion($id) |
||
81 | |||
82 | /** |
||
83 | * @param int $keep |
||
84 | */ |
||
85 | public function removeOldVersions(int $keep): void |
||
93 | |||
94 | public function removeAllVersions() |
||
98 | |||
99 | /** |
||
100 | * @return bool |
||
101 | */ |
||
102 | public function shouldVersioning(): bool |
||
106 | |||
107 | /** |
||
108 | * @return array |
||
109 | */ |
||
110 | public function getVersionableAttributes(): array |
||
120 | |||
121 | /** |
||
122 | * @param array $attributes |
||
123 | * |
||
124 | * @return $this |
||
125 | * |
||
126 | * @throws \Exception |
||
127 | */ |
||
128 | public function setVersionable(array $attributes) |
||
138 | |||
139 | /** |
||
140 | * @param array $attributes |
||
141 | * |
||
142 | * @return $this |
||
143 | * |
||
144 | * @throws \Exception |
||
145 | */ |
||
146 | public function setDontVersionable(array $attributes) |
||
156 | |||
157 | /** |
||
158 | * @return array |
||
159 | */ |
||
160 | public function getVersionable(): array |
||
164 | |||
165 | /** |
||
166 | * @return array |
||
167 | */ |
||
168 | public function getDontVersionable(): array |
||
172 | |||
173 | /** |
||
174 | * @return string |
||
175 | */ |
||
176 | public function getVersionModel(): string |
||
180 | |||
181 | /** |
||
182 | * @return string |
||
183 | */ |
||
184 | public function getKeepVersionsCount(): string |
||
188 | |||
189 | /** |
||
190 | * Get the versionable attributes of a given array. |
||
191 | * |
||
192 | * @param array $attributes |
||
193 | * |
||
194 | * @return array |
||
195 | */ |
||
196 | public function versionableFromArray(array $attributes): array |
||
208 | } |
||
209 |
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.