File tree 3 files changed +41
-3
lines changed
3 files changed +41
-3
lines changed Original file line number Diff line number Diff line change @@ -91,9 +91,13 @@ public function attributeValuesToBeLogged(string $processingEvent): array
91
91
}
92
92
93
93
$ properties ['attributes ' ] = static ::logChanges (
94
- $ this ->exists
95
- ? $ this ->fresh () ?? $ this
96
- : $ this
94
+ $ processingEvent == 'retrieved '
95
+ ? $ this
96
+ : (
97
+ $ this ->exists
98
+ ? $ this ->fresh () ?? $ this
99
+ : $ this
100
+ )
97
101
);
98
102
99
103
if (static ::eventsToBeRecorded ()->contains ('updated ' ) && $ processingEvent == 'updated ' ) {
Original file line number Diff line number Diff line change 7
7
use Illuminate \Support \Collection ;
8
8
use Spatie \Activitylog \Models \Activity ;
9
9
use Spatie \Activitylog \Test \Models \Article ;
10
+ use Spatie \Activitylog \Test \Models \Issue733 ;
10
11
use Spatie \Activitylog \Test \Models \User ;
11
12
use Spatie \Activitylog \Traits \LogsActivity ;
12
13
@@ -423,6 +424,21 @@ public function it_will_submit_a_log_with_json_changes()
423
424
$ this ->assertSame ($ expectedChanges , $ changes );
424
425
}
425
426
427
+ /** @test */
428
+ public function it_will_log_the_retrieval_of_the_model ()
429
+ {
430
+ $ article = Issue733::create (['name ' => 'my name ' ]);
431
+
432
+ $ retrieved = Issue733::whereKey ($ article ->getKey ())->first ();
433
+ $ this ->assertTrue ($ article ->is ($ retrieved ));
434
+
435
+ $ activity = $ this ->getLastActivity ();
436
+
437
+ $ this ->assertInstanceOf (get_class ($ article ), $ activity ->subject );
438
+ $ this ->assertTrue ($ article ->is ($ activity ->subject ));
439
+ $ this ->assertEquals ('retrieved ' , $ activity ->description );
440
+ }
441
+
426
442
public function loginWithFakeUser ()
427
443
{
428
444
$ user = new $ this ->user ();
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Spatie \Activitylog \Test \Models ;
4
+
5
+ use Spatie \Activitylog \Traits \LogsActivity ;
6
+
7
+ class Issue733 extends Article
8
+ {
9
+ use LogsActivity;
10
+
11
+ protected static $ recordEvents = [
12
+ 'retrieved ' ,
13
+ ];
14
+
15
+ protected static $ submitEmptyLogs = false ;
16
+ protected static $ logAttributes = ['name ' ];
17
+ public static $ logOnlyDirty = false ;
18
+ }
You can’t perform that action at this time.
0 commit comments