1 | <?php |
||
10 | trait RollbackRevisionJsonRepresentation |
||
11 | { |
||
12 | /** |
||
13 | * Only rollback the model instance to the given revision. |
||
14 | * |
||
15 | * Loop through the revision's data. |
||
16 | * If the revision's field name matches one from the model's attributes. |
||
17 | * Replace the value from the model's attribute with the one from the revision. |
||
18 | * |
||
19 | * @param RevisionModelContract $revision |
||
20 | * @return void |
||
21 | */ |
||
22 | protected function rollbackModelToRevision(RevisionModelContract $revision): void |
||
32 | |||
33 | /** |
||
34 | * Only rollback the model's direct relations to the given revision. |
||
35 | * |
||
36 | * Loop through the stored revision's relation items. |
||
37 | * If the relation exists, then update it with the data from the revision. |
||
38 | * If the relation does not exist, then create a new one with the data from the revision. |
||
39 | * |
||
40 | * Please note that when creating a new relation, the primary key (id) will be the old one from the revision's data. |
||
41 | * This way, the correspondence between the model and it's relation is kept. |
||
42 | * |
||
43 | * @param string $relation |
||
44 | * @param array $attributes |
||
45 | * @return void |
||
46 | */ |
||
47 | protected function rollbackDirectRelationToRevision(string $relation, array $attributes): void |
||
87 | |||
88 | /** |
||
89 | * Rollback a model's pivoted relations to the given revision. |
||
90 | * |
||
91 | * Loop through the stored revision's relation items. |
||
92 | * If the relation's related model exists, then leave it as is (maybe modified) because other records or entities might be using it. |
||
93 | * If the relation's related model does not exist, then create a new one with the data from the revision. |
||
94 | * |
||
95 | * Please note that when creating a new relation related instance, the primary key (id) will be the old one from the revision's data. |
||
96 | * This way, the correspondence between the model and it's relation is kept. |
||
97 | * |
||
98 | * Loop through the stored revision's relation pivots. |
||
99 | * Sync the model's pivot values with the ones from the revision. |
||
100 | * |
||
101 | * @param string $relation |
||
102 | * @param array $attributes |
||
103 | * @return void |
||
104 | */ |
||
105 | protected function rollbackPivotedRelationToRevision(string $relation, array $attributes): void |
||
142 | } |
||
143 |
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: