Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/Drivers/MySQLDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ private function validateEntityType(string $entityType): void
{
// Skip validation in testing environment to allow fake class names
if (app()->environment('testing')) {

return;
}

Expand All @@ -73,6 +74,7 @@ public function store(AuditLogInterface $log): void

try {
$model = EloquentAuditLog::forEntity(entityClass: $log->getEntityType());
$model->setConnection(config('audit-logger.default'));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider using the cached configuration value $this->config['default'] instead of calling config() directly here. The configuration is already loaded and cached in the constructor for consistency and minor performance benefit.

$model->setConnection($this->config['default']);

$model->fill([
'entity_id' => $log->getEntityId(),
'action' => $log->getAction(),
Expand Down Expand Up @@ -116,6 +118,7 @@ public function storeBatch(array $logs): void
// Use Eloquent models to leverage automatic JSON casting
foreach ($entityLogs as $log) {
$model = EloquentAuditLog::forEntity(entityClass: $entityType);
$model->setConnection(config('audit-logger.default'));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similar to the store method, using the cached configuration value $this->config['default'] is preferred over calling config() directly.

$model->setConnection($this->config['default']);

$model->fill([
'entity_id' => $log->getEntityId(),
'action' => $log->getAction(),
Expand All @@ -137,7 +140,7 @@ public function createStorageForEntity(string $entityClass): void
$this->validateEntityType($entityClass);
$tableName = $this->getTableName($entityClass);

Schema::create($tableName, function (Blueprint $table) {
Schema::connection(config('audit-logger.default'))->create($tableName, function (Blueprint $table) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Use the cached configuration value $this->config['default'] for the database connection when creating the schema.

Schema::connection($this->config['default'])->create($tableName, function (Blueprint $table) {

$table->id();
$table->string('entity_id');
$table->string('action');
Expand Down Expand Up @@ -176,7 +179,7 @@ public function storageExistsForEntity(string $entityClass): bool
}

// Check database and cache the result
$exists = Schema::hasTable($tableName);
$exists = Schema::connection(config('audit-logger.default'))->hasTable($tableName);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Use the cached configuration value $this->config['default'] for the database connection when checking if the table exists.

$exists = Schema::connection($this->config['default'])->hasTable($tableName);

self::$existingTables[$tableName] = $exists;

return $exists;
Expand Down
Loading