@@ -382,6 +382,50 @@ public function handle(EventLogBag $event, Closure $next): EventLogBag
382382 $ this ->assertEquals ($ expectedChanges , $ this ->getLastActivity ()->changes ()->toArray ());
383383});
384384
385+ it ('can block activity entry when pipe modification empties changes ' , function () {
386+ $ articleClass = new class () extends Article {
387+ use LogsActivity;
388+
389+ public function getActivitylogOptions (): LogOptions
390+ {
391+ return LogOptions::defaults ()
392+ ->dontSubmitEmptyLogs ()
393+ ->logOnly (['name ' , 'text ' , 'user.name ' ]);
394+ }
395+ };
396+
397+ $ user = User::create ([
398+ 'name ' => 'user name ' ,
399+ ]);
400+
401+ $ articleClass ::addLogChange (new class () implements LoggablePipe {
402+ public function handle (EventLogBag $ event , Closure $ next ): EventLogBag
403+ {
404+ if ('updated ' === $ event ->event ) {
405+ $ event ->changes = [
406+ 'attributes ' => [],
407+ 'old ' => [],
408+ ];
409+ }
410+
411+ return $ next ($ event );
412+ }
413+ });
414+
415+ $ article = $ articleClass ::create ([
416+ 'name ' => 'original name ' ,
417+ 'text ' => 'original text ' ,
418+ 'user_id ' => $ user ->id ,
419+ ]);
420+
421+ $ article ->name = 'updated name ' ;
422+ $ article ->text = 'updated text ' ;
423+ $ article ->save ();
424+
425+ $ this ->assertEquals (1 , Activity::query ()->count (), 'Only the created event should be present ' );
426+ $ this ->assertEquals ('created ' , $ this ->getLastActivity ()->event );
427+ });
428+
385429it ('can store empty relation when creating a model ' , function () {
386430 $ articleClass = new class () extends Article {
387431 use LogsActivity;
0 commit comments