File tree Expand file tree Collapse file tree 2 files changed +48
-0
lines changed Expand file tree Collapse file tree 2 files changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -59,6 +59,11 @@ public static function boot()
59
59
$ model ->auditUpdate ();
60
60
});
61
61
62
+ static ::created (function ($ model )
63
+ {
64
+ $ model ->auditCreation ();
65
+ });
66
+
62
67
static ::deleted (function ($ model )
63
68
{
64
69
$ model ->prepareAudit ();
@@ -126,6 +131,25 @@ public function prepareAudit()
126
131
}
127
132
}
128
133
134
+ /**
135
+ * Audit creation
136
+ */
137
+ public function auditCreation ()
138
+ {
139
+ if ((!isset ($ this ->auditEnabled ) || $ this ->auditEnabled ))
140
+ {
141
+ return $ this ->audit ([
142
+ 'old_value ' => null ,
143
+ 'new_value ' => $ this ->updatedData ,
144
+ 'owner_type ' => get_class ($ this ),
145
+ 'owner_id ' => $ this ->getKey (),
146
+ 'user_id ' => $ this ->getUserId (),
147
+ 'created_at ' => new \DateTime (),
148
+ 'updated_at ' => new \DateTime (),
149
+ ]);
150
+ }
151
+ }
152
+
129
153
/**
130
154
* Listener pos save
131
155
*/
Original file line number Diff line number Diff line change @@ -52,6 +52,11 @@ public static function bootAuditingTrait()
52
52
$ model ->auditUpdate ();
53
53
});
54
54
55
+ static ::created (function ($ model )
56
+ {
57
+ $ model ->auditCreation ();
58
+ });
59
+
55
60
static ::deleted (function ($ model )
56
61
{
57
62
$ model ->prepareAudit ();
@@ -118,6 +123,25 @@ public function prepareAudit()
118
123
}
119
124
}
120
125
126
+ /**
127
+ * Audit creation
128
+ */
129
+ public function auditCreation ()
130
+ {
131
+ if ((!isset ($ this ->auditEnabled ) || $ this ->auditEnabled ))
132
+ {
133
+ return $ this ->audit ([
134
+ 'old_value ' => null ,
135
+ 'new_value ' => $ this ->updatedData ,
136
+ 'owner_type ' => get_class ($ this ),
137
+ 'owner_id ' => $ this ->getKey (),
138
+ 'user_id ' => $ this ->getUserId (),
139
+ 'created_at ' => new \DateTime (),
140
+ 'updated_at ' => new \DateTime (),
141
+ ]);
142
+ }
143
+ }
144
+
121
145
/**
122
146
* Listener pos save
123
147
*/
You can’t perform that action at this time.
0 commit comments