lthn.io/app/Mod/Names/Models/NameActivity.php
Claude 14f4d1fdc0
feat: activity logging for name operations
NameActivity model with log() static method. Stores event, name,
properties (JSON), and hashed IP (GDPR). SubmitClaim action now
logs 'claimed' event. Ready for dns_updated, registered, etc.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 11:46:31 +01:00

55 lines
1.3 KiB
PHP

<?php
declare(strict_types=1);
namespace Mod\Names\Models;
use Illuminate\Database\Eloquent\Model;
/**
* Activity log for name operations.
*
* NameActivity::log('mybrand', 'registered', ['address' => '...']);
* NameActivity::log('mybrand', 'dns_updated', ['records' => [...]]);
* $recent = NameActivity::forName('mybrand')->latest()->get();
*/
class NameActivity extends Model
{
public $timestamps = false;
protected $table = 'name_activity';
protected $fillable = [
'name',
'event',
'properties',
'ip_hash',
'created_at',
];
protected $casts = [
'properties' => 'array',
'created_at' => 'datetime',
];
public function scopeForName($query, string $name)
{
return $query->where('name', $name);
}
/**
* Log a name activity event.
*
* NameActivity::log('mybrand', 'claimed', ['email' => 'me@example.com']);
*/
public static function log(string $name, string $event, array $properties = [], ?string $ip = null): self
{
return static::create([
'name' => $name,
'event' => $event,
'properties' => $properties,
'ip_hash' => $ip ? hash('sha256', $ip) : null,
'created_at' => now(),
]);
}
}