@@ -56,6 +56,7 @@ private function validateEntityType(string $entityType): void
5656 {
5757 // Skip validation in testing environment to allow fake class names
5858 if (app ()->environment ('testing ' )) {
59+
5960 return ;
6061 }
6162
@@ -73,6 +74,7 @@ public function store(AuditLogInterface $log): void
7374
7475 try {
7576 $ model = EloquentAuditLog::forEntity (entityClass: $ log ->getEntityType ());
77+ $ model ->setConnection (config ('audit-logger.default ' ));
7678 $ model ->fill ([
7779 'entity_id ' => $ log ->getEntityId (),
7880 'action ' => $ log ->getAction (),
@@ -116,6 +118,7 @@ public function storeBatch(array $logs): void
116118 // Use Eloquent models to leverage automatic JSON casting
117119 foreach ($ entityLogs as $ log ) {
118120 $ model = EloquentAuditLog::forEntity (entityClass: $ entityType );
121+ $ model ->setConnection (config ('audit-logger.default ' ));
119122 $ model ->fill ([
120123 'entity_id ' => $ log ->getEntityId (),
121124 'action ' => $ log ->getAction (),
@@ -137,7 +140,7 @@ public function createStorageForEntity(string $entityClass): void
137140 $ this ->validateEntityType ($ entityClass );
138141 $ tableName = $ this ->getTableName ($ entityClass );
139142
140- Schema::create ($ tableName , function (Blueprint $ table ) {
143+ Schema::connection ( config ( ' audit-logger.default ' ))-> create ($ tableName , function (Blueprint $ table ) {
141144 $ table ->id ();
142145 $ table ->string ('entity_id ' );
143146 $ table ->string ('action ' );
@@ -176,7 +179,7 @@ public function storageExistsForEntity(string $entityClass): bool
176179 }
177180
178181 // Check database and cache the result
179- $ exists = Schema::hasTable ($ tableName );
182+ $ exists = Schema::connection ( config ( ' audit-logger.default ' ))-> hasTable ($ tableName );
180183 self ::$ existingTables [$ tableName ] = $ exists ;
181184
182185 return $ exists ;
0 commit comments