Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ For this reason, we've developed the notion of custom resolvers. They must be im
These custom resolvers don't run as items are entered, due to the load increase. This should arguably be queued, but easier on implementations for a command (cron) system. Use the Laravel Scheduler to execute our command.

```php
$schedule->command('logger:audit-resolver')
Schedule::command('logger:audit-resolver')
->hourly()
->withoutOverlapping();
```
Expand Down
9 changes: 5 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
"illuminate/support": "^11.0",
"illuminate/translation": "^11.0"
},
"require-dev": {
"orchestra/testbench": "^9.5",
"phpunit/phpunit": "^11.2",
"squizlabs/php_codesniffer": "^3.10"
},
"autoload": {
"psr-4": {
"Sourcetoad\\Logger\\": "src"
Expand All @@ -42,9 +47,5 @@
"Logger": "Sourcetoad\\Logger\\LoggerFacade"
}
}
},
"require-dev": {
"squizlabs/php_codesniffer": "^3.10",
"phpunit/phpunit": "^11.2"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,13 @@ public function up(): void
->onDelete('RESTRICT');
});

DB::statement('ALTER TABLE `audit_activities` ADD `ip_address` VARBINARY(16) AFTER `type`');
if (DB::getDriverName() === 'pgsql') {
// PostgreSQL-specific SQL
DB::statement('ALTER TABLE audit_activities ADD ip_address INET');
} else {
// MySQL-specific SQL
DB::statement('ALTER TABLE `audit_activities` ADD `ip_address` VARBINARY(16) AFTER `type`');
}

Schema::create('audit_models', function (Blueprint $table) {
$table->bigIncrements('id');
Expand Down
11 changes: 10 additions & 1 deletion src/Models/AuditActivity.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Exception;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\MorphTo;
use Illuminate\Support\Facades\DB;
use Sourcetoad\Logger\Enums\ActivityType;
use Sourcetoad\Logger\Enums\HttpVerb;
use Sourcetoad\Logger\Logger;
Expand Down Expand Up @@ -57,11 +58,19 @@ class AuditActivity extends BaseModel

protected function setIpAddressAttribute(?string $value): void
{
$this->attributes['ip_address'] = inet_pton((string)$value);
if (DB::getDriverName() === 'pgsql') {
$this->attributes['ip_address'] = $value;
} else {
$this->attributes['ip_address'] = inet_pton((string)$value);
}
}

protected function getIpAddressAttribute($value): string
{
if (DB::getDriverName() === 'pgsql') {
return strtoupper($value);
}

return strtoupper(inet_ntop($value));
}

Expand Down
3 changes: 2 additions & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@

use Sourcetoad\Logger\LoggerFacade;
use Sourcetoad\Logger\LoggerServiceProvider;
use Orchestra\Testbench\TestCase as TestBenchTestCase;

class TestCase extends \PHPUnit\Framework\TestCase
class TestCase extends TestBenchTestCase
{
protected function getPackageProviders($app): array
{
Expand Down