44
55namespace iamfarhad \LaravelAuditLog \Drivers ;
66
7- use iamfarhad \LaravelAuditLog \Contracts \AuditDriverInterface ;
8- use iamfarhad \LaravelAuditLog \Contracts \AuditLogInterface ;
9- use iamfarhad \LaravelAuditLog \Models \AuditLog ;
10- use Illuminate \Database \Connection ;
11- use Illuminate \Database \Query \Builder ;
12- use Illuminate \Database \Schema \Blueprint ;
7+ use Illuminate \Support \Str ;
138use Illuminate \Support \Carbon ;
14- use Illuminate \Support \ Facades \ DB ;
9+ use Illuminate \Database \ Connection ;
1510use Illuminate \Support \Facades \Log ;
11+ use Illuminate \Database \Query \Builder ;
1612use Illuminate \Support \Facades \Schema ;
17- use Illuminate \Support \Str ;
13+ use Illuminate \Database \Schema \Blueprint ;
14+ use iamfarhad \LaravelAuditLog \Models \AuditLog ;
15+ use iamfarhad \LaravelAuditLog \Contracts \AuditLogInterface ;
16+ use iamfarhad \LaravelAuditLog \Contracts \AuditDriverInterface ;
1817
1918final class MySQLDriver implements AuditDriverInterface
2019{
2120 private Connection $ connection ;
21+
2222 private string $ tablePrefix ;
23+
2324 private string $ tableSuffix ;
2425
2526 public function __construct (array $ config = [])
@@ -35,7 +36,7 @@ public function store(AuditLogInterface $log): void
3536 Log::info ('Entering store method for audit log ' , [
3637 'entity_type ' => $ log ->getEntityType (),
3738 'entity_id ' => $ log ->getEntityId (),
38- 'action ' => $ log ->getAction ()
39+ 'action ' => $ log ->getAction (),
3940 ]);
4041
4142 $ tableName = $ this ->getTableName ($ log ->getEntityType ());
@@ -54,14 +55,14 @@ public function store(AuditLogInterface $log): void
5455 Log::debug ('Audit log inserted into database ' , [
5556 'table ' => $ tableName ,
5657 'entity_id ' => $ log ->getEntityId (),
57- 'action ' => $ log ->getAction ()
58+ 'action ' => $ log ->getAction (),
5859 ]);
5960 } catch (\Exception $ e ) {
6061 Log::error ('Failed to store audit log in database ' , [
6162 'table ' => $ tableName ,
6263 'entity_id ' => $ log ->getEntityId (),
6364 'error ' => $ e ->getMessage (),
64- 'trace ' => $ e ->getTraceAsString ()
65+ 'trace ' => $ e ->getTraceAsString (),
6566 ]);
6667 throw $ e ;
6768 }
@@ -70,8 +71,8 @@ public function store(AuditLogInterface $log): void
7071 /**
7172 * Legacy method to maintain interface compatibility.
7273 * Simply stores logs one by one instead of in batch.
73- *
74- * @param array<AuditLogInterface> $logs
74+ *
75+ * @param array<AuditLogInterface> $logs
7576 */
7677 public function storeBatch (array $ logs ): void
7778 {
@@ -84,7 +85,7 @@ public function getLogsForEntity(string $entityType, string|int $entityId, array
8485 {
8586 $ tableName = $ this ->getTableName ($ entityType );
8687
87- if (!Schema::hasTable ($ tableName )) {
88+ if (! Schema::hasTable ($ tableName )) {
8889 return [];
8990 }
9091
@@ -148,11 +149,11 @@ public function storageExistsForEntity(string $entityClass): bool
148149 */
149150 public function ensureStorageExists (string $ entityClass ): void
150151 {
151- if (!config ('audit-logger.auto_migration ' , true )) {
152+ if (! config ('audit-logger.auto_migration ' , true )) {
152153 return ;
153154 }
154155
155- if (!$ this ->storageExistsForEntity ($ entityClass )) {
156+ if (! $ this ->storageExistsForEntity ($ entityClass )) {
156157 $ this ->createStorageForEntity ($ entityClass );
157158 }
158159 }
@@ -165,7 +166,7 @@ private function getTableName(string $entityType): string
165166 // Handle pluralization
166167 $ tableName = Str::plural ($ className );
167168
168- return $ this ->tablePrefix . $ tableName . $ this ->tableSuffix ;
169+ return $ this ->tablePrefix . $ tableName. $ this ->tableSuffix ;
169170 }
170171
171172 private function applyFilters (Builder $ query , array $ options ): void
0 commit comments