5
5
use Illuminate \Database \Eloquent \Model ;
6
6
use Illuminate \Database \Eloquent \Relations \MorphMany ;
7
7
use Illuminate \Database \Eloquent \SoftDeletes ;
8
- use Illuminate \Support \Arr ;
9
- use Illuminate \Support \Facades \Config ;
8
+ use Scrn \Journal \Events \ActivityPrepared ;
10
9
use Scrn \Journal \Models \Activity ;
11
10
12
11
trait LogsActivity
@@ -37,7 +36,9 @@ protected static function bootLogsActivity()
37
36
38
37
list ($ old_data , $ new_data ) = method_exists ($ model , $ attributeGetter ) ? $ model ->$ attributeGetter (...func_get_args ()) : null ;
39
38
40
- $ model ->transformActivity (journal ()->action ($ event )->on ($ model )->data ($ old_data , $ new_data )->toActivity ())->save ();
39
+ $ activity = $ model ->transformActivity (journal ()->action ($ event )->on ($ model )->data ($ old_data , $ new_data )->toActivity ());
40
+
41
+ event (new ActivityPrepared ($ activity ));
41
42
});
42
43
}
43
44
}
@@ -51,7 +52,7 @@ public function getCreatedEventAttributes(): array
51
52
{
52
53
$ attributes = [];
53
54
54
- foreach ($ this ->attributes as $ attribute => $ value ) {
55
+ foreach ($ this ->getAttributes () as $ attribute => $ value ) {
55
56
if ($ this ->shouldAttributeBeLogged ($ attribute )) {
56
57
$ attributes [$ attribute ] = $ value ;
57
58
}
@@ -73,7 +74,7 @@ public function getUpdatedEventAttributes(): array
73
74
$ old = [];
74
75
$ new = [];
75
76
76
- foreach (array_merge ( $ this ->getDirty (), $ this -> getChanges () ) as $ attribute => $ value ) {
77
+ foreach ($ this ->getDirty () as $ attribute => $ value ) {
77
78
if ($ this ->shouldAttributeBeLogged ($ attribute )) {
78
79
$ old [$ attribute ] = $ this ->getOriginal ($ attribute );
79
80
$ new [$ attribute ] = $ this ->getAttribute ($ attribute );
@@ -95,7 +96,7 @@ public function getDeletedEventAttributes(): array
95
96
{
96
97
$ attributes = [];
97
98
98
- foreach ($ this ->attributes as $ attribute => $ value ) {
99
+ foreach ($ this ->getAttributes () as $ attribute => $ value ) {
99
100
if ($ this ->shouldAttributeBeLogged ($ attribute )) {
100
101
$ attributes [$ attribute ] = $ value ;
101
102
}
@@ -124,7 +125,7 @@ public function getRestoredEventAttributes(): array
124
125
*/
125
126
public function getLoggedEvents (): array
126
127
{
127
- $ events = Config:: get ('journal.events ' , ['created ' , 'updated ' , 'deleted ' ]);
128
+ $ events = config ()-> get ('journal.events ' , ['created ' , 'updated ' , 'deleted ' ]);
128
129
129
130
if (in_array (SoftDeletes::class, class_uses_recursive (static ::class))) {
130
131
$ events [] = 'restored ' ;
@@ -134,9 +135,7 @@ public function getLoggedEvents(): array
134
135
$ events = array_merge ($ events , ['pivotAttached ' , 'pivotDetached ' , 'pivotUpdated ' ]);
135
136
}
136
137
137
- if (isset ($ this ->logged )) {
138
- $ events = array_merge ($ events , $ this ->logged ?? []);
139
- }
138
+ $ events = array_merge ($ events , $ this ->logged ?? []);
140
139
141
140
return $ events ;
142
141
}
@@ -185,7 +184,7 @@ public function getIgnoredAttributes(): array
185
184
*/
186
185
public function shouldLogTimestamps (): bool
187
186
{
188
- return $ this ->logTimestamps ?? Config:: get ('journal.timestamps ' , false );
187
+ return $ this ->logTimestamps ?? config ()-> get ('journal.timestamps ' , false );
189
188
}
190
189
191
190
/**
@@ -214,7 +213,7 @@ public function shouldLogEvent(string $event): bool
214
213
*/
215
214
public function getOriginalRelation (string $ key , $ default = null )
216
215
{
217
- return Arr:: get ($ this ->originalRelations , $ key , $ default );
216
+ return array_get ($ this ->originalRelations , $ key , $ default );
218
217
}
219
218
220
219
/**
0 commit comments