You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+31-4Lines changed: 31 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -74,7 +74,7 @@ Recommended action is creating an enum class to describe all models in your syst
74
74
75
75
This enforces the user to create shorthand notation for all models to cut down on database size. If a numeric morph is not found, the system will fail out. Due to issues with blindly overwriting and applying these morphs globally, they are manually applied. This means that morphs in your application are left untouched.
76
76
77
-
#### Trackable Trait
77
+
#### Trackable Trait and Contract
78
78
For models that may contain information that you wish to be notified was accessed or mutated. You may add the `Trackable` trait and contract to these models:
79
79
80
80
```php
@@ -85,7 +85,13 @@ use Sourcetoad\Logger\Traits\Trackable;
85
85
class TrackedModel extends Model implements TrackableContract {
86
86
use Trackable;
87
87
88
-
// Tracked models must implement this function
88
+
// Tracked models must implement these functions
89
+
90
+
public function getOwnerRelationshipName(): ?string
91
+
{
92
+
//
93
+
}
94
+
89
95
public function trackableOwnerResolver(): ?Model
90
96
{
91
97
//
@@ -130,7 +136,7 @@ class TrackedModel extends Model implements TrackableContract {
This will run taking 200 items of both changes and retrieved models. It will identify the owner associated with the model through the `Trackable` contract. The functions for each individual model should be easy.
156
162
157
163
```php
164
+
public function getOwnerRelationshipName(): string
165
+
{
166
+
return 'object.relation.owner';
167
+
}
168
+
158
169
public function trackableOwnerResolver(): Owner
159
170
{
160
171
return $this->object->relation->owner;
161
172
}
162
173
```
163
174
164
-
As you can see, we have to traverse whatever relation/property we need in order to relate the model at hand to an owner. If there is no match, you probably shouldn't be logging it.
175
+
As you can see, we have to traverse whatever relation/property we need in order to relate the model at hand to an owner.
176
+
177
+
However, there may be cases where a tracked model is also the owner of that model. In those cases, there is no relation/property to traverse.
178
+
179
+
```php
180
+
public function getOwnerRelationshipName(): null
181
+
{
182
+
return null;
183
+
}
184
+
185
+
public function trackableOwnerResolver(): TrackedModel
186
+
{
187
+
return $this;
188
+
}
189
+
```
190
+
191
+
If neither of these scenarios match, you probably shouldn't be logging it.
0 commit comments