@@ -12,43 +12,51 @@ class AuditLogObserver
1212 */
1313 public function created (Model $ model ): void
1414 {
15- $ this ->getAuditLogModel ($ model )
16- ->recordChanges (EventType::CREATED , $ model );
15+ if ($ model ->auditEventAllowed ($ model ::AUDIT_EVENT_CREATED )) {
16+ $ this ->getAuditLogModel ($ model )
17+ ->recordChanges (EventType::CREATED , $ model );
18+ }
1719 }
1820
1921 /**
2022 * @param Model $model
2123 */
2224 public function updated (Model $ model ): void
2325 {
24- $ this ->getAuditLogModel ($ model )
25- ->recordChanges (EventType::UPDATED , $ model );
26+ if ($ model ->auditEventAllowed ($ model ::AUDIT_EVENT_UPDATED )) {
27+ $ this ->getAuditLogModel ($ model )
28+ ->recordChanges (EventType::UPDATED , $ model );
29+ }
2630 }
2731
2832 /**
2933 * @param Model $model
3034 */
3135 public function deleted (Model $ model ): void
3236 {
33- /*
34- * If a model is hard deleting, either via a force delete or that model does not implement
35- * the SoftDeletes trait we should tag it as such so logging doesn't occur down the pipe.
36- */
37- if ((! method_exists ($ model , 'isForceDeleting ' ) || $ model ->isForceDeleting ())) {
38- $ event = EventType::FORCE_DELETED ;
39- }
37+ if ($ model ->auditEventAllowed ($ model ::AUDIT_EVENT_DELETED )) {
38+ /*
39+ * If a model is hard deleting, either via a force delete or that model does not implement
40+ * the SoftDeletes trait we should tag it as such so logging doesn't occur down the pipe.
41+ */
42+ if ((!method_exists ($ model , 'isForceDeleting ' ) || $ model ->isForceDeleting ())) {
43+ $ event = EventType::FORCE_DELETED ;
44+ }
4045
41- $ this ->getAuditLogModel ($ model )
42- ->recordChanges ($ event ?? EventType::DELETED , $ model );
46+ $ this ->getAuditLogModel ($ model )
47+ ->recordChanges ($ event ?? EventType::DELETED , $ model );
48+ }
4349 }
4450
4551 /**
4652 * @param Model $model
4753 */
4854 public function restored (Model $ model ): void
4955 {
50- $ this ->getAuditLogModel ($ model )
51- ->recordChanges (EventType::RESTORED , $ model );
56+ if ($ model ->auditEventAllowed ($ model ::AUDIT_EVENT_RESTORED )) {
57+ $ this ->getAuditLogModel ($ model )
58+ ->recordChanges (EventType::RESTORED , $ model );
59+ }
5260 }
5361
5462 /**
0 commit comments